Larry Jing
Larry Jing

Reputation: 404

Make textview take up half of the width of the screen with relativelayout

I have a TextView that I want to have 1/8 of the whole screen, and dp just works to get half of the height but how do I get the 4 TextView's to each share the bottom half of the screen equally? Right now they share the height equally, but the ones on the left are wider than the ones on the right.

Upvotes: 1

Views: 1484

Answers (2)

Gabe Sechan
Gabe Sechan

Reputation: 93561

You can't with a relative layout- consider a PercentRelativeLayout

Upvotes: -1

Nick Friskel
Nick Friskel

Reputation: 2437

Inside of your RelativeLayout you need to make a horizontal LinearLayout just for these TextView's. Then to make them all take up an equal amount of space, assign an equal weight to them all with weight="1".

If you want a TextView to take up more or less space than the others, just assign a proportionate weight to it. For example if you have 4 views and want the first one to take up 1/2 of the space and the other 3 to share the rest equally, set the weight of the first view to 3 and the others to 1.

Upvotes: 2

Related Questions