I am adding two views to a linearlayout. When I click on the first view it has to occupy second views width also. How do I do that?
Asked
Active
Viewed 2.0k times
2 Answers
3
This code sets the width and height of yourView that was placed inside a RelativeLayout.
int viewWidth = 69;
int viewHeight = 69;
RelativeLayout.LayoutParams newViewParams = new RelativeLayout.LayoutParams(viewWidth, viewHeight);
View v = (View)findViewById(R.id.yourView);
v.setLayoutParams(newViewParams);
Alternatively, for a LinearLayout, you need to use this:
LinearLayout.LayoutParams newViewParams = new LinearLayout.LayoutParams(viewWidth, viewHeight);

DoruChidean
- 7,941
- 1
- 29
- 33
2
Why don't you just set second view's visibility to View.GONE in View1 onClickListener? That's simpler and faster than adjusting first view's width

Chaosit
- 1,116
- 7
- 21