When trying to render the following RelativeLayout
on smaller screen sizes. In the graphical layout editor, the second TextView
is completely hidden, but the first one is fully expanded showing the complete text contents. I understand that TextViews
are supposed to be scrollable.
Is there any way to use RelativeLayout
and give each an equal portion of the screen, or should I just use a LinearLayout
and use layout_weight
? From the guidance in the Android documentation, I was under the impression I should avoid using LinearLayout
in favor of RelativeLayout
.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:fillViewport="true"
android:gravity="center"
android:text="Lorem ipsum dolor sit amet, onsectetur adipiscing elit. Curabitur molestie tempor ante non interdum. Nullam sit amet diam ligula. Suspendisse ultricies commodo felis in rutrum. Lorem ipsum dolor sit amet, onsectetur adipiscing elit. Curabitur molestie tempor ante non interdum. Nullam sit amet diam ligula. Suspendisse ultricies commodo felis in rutrum.Lorem ipsum dolor sit amet, onsectetur adipiscing elit. Curabitur molestie tempor ante non interdum. Nullam sit amet diam ligula. Suspendisse ultricies commodo felis in rutrum."
android:scrollbars="vertical"
android:maxlines="100"
android:textSize="22dp" >
</TextView>
<TextView
android:id="@+id/tv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv1"
android:fillViewport="true"
android:gravity="center"
android:scrollbars="vertical"
android:maxlines="100"
android:text="Lorem ipsum dolor sit amet, onsectetur adipiscing elit. Curabitur molestie tempor ante non interdum. Nullam sit amet diam ligula. Suspendisse ultricies commodo felis in rutrum. Lorem ipsum dolor sit amet, onsectetur adipiscing elit. Curabitur molestie tempor ante non interdum. Nullam sit amet diam ligula. Suspendisse ultricies commodo felis in rutrum.Lorem ipsum dolor sit amet, onsectetur adipiscing elit. Curabitur molestie tempor ante non interdum. Nullam sit amet diam ligula. Suspendisse ultricies commodo felis in rutrum."
android:textSize="22dp" />
</RelativeLayout>
Since you used "wrap_content" in the first TextView, it fills all the space available then there is no space left for the second TextView. if you wish to have them both, then you can put them inside a LinearLayout with equal weights or you can specify a certain size in the "layout_height" field. P.S. If you want them to be equal on all devices then LinearLayout is your best bet. Also you can have the LinearLayout inside the RelativeLayout in case you want to add any other widgets relative to them.