2

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?

2 Answers 2

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); 
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.