Shay
Shay

Reputation: 1405

Inserting many views into one layout without them overflowing to the end of the screen

I'm looking for a way that I can dynamically add views into a layout (currently a LinearLayout) and that they won't overflow into the end of the screen and be hidden.

I can't use ScrollViews since it has to look like one sentence (It's a "fill the blanks" question).

I'm just looking for an idea on how to do this, not the code itself.

Thanks in advance, Shay.

Upvotes: 1

Views: 99

Answers (1)

Rohit Sharma
Rohit Sharma

Reputation: 2017

If you are using linear layout than use linear layout with weights:

For example: You have a LinearLayout with vertical orientation and you have 2 ImageViews inside it and you want these ImageViews always to take equal space.

<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:weightSum="2" android:orientation="vertical" android:layout_gravity="center">

You can set the layout_weight of each ImageView to 1 and the weightSum in LinearLayout to 2 to achieve this.

<ImageView android:layout_height="wrap_content"
android:layout_weight="1" android:layout_height="0dp"/>

This will work correctly for any device without overflow into the end of the screen and be hidden

Upvotes: 3

Related Questions