There is a layout:

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@android:color/white"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"> <ImageView android:id="@+id/view1" android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:src="@drawable/image"/> <LinearLayout android:id="@+id/parent_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignBottom="@+id/view1" android:layout_alignTop="@+id/view1" android:orientation="horizontal" android:background="@android:color/holo_blue_light"> <View android:id="@+id/view2" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1"/> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:text="Текст" android:textColor="@android:color/background_dark" android:gravity="center" android:textSize="40sp" android:background="@android:color/holo_green_light"/> </LinearLayout> <View android:id="@+id/view3" android:layout_width="match_parent" android:layout_height="2000dp" /> </RelativeLayout> </ScrollView> 

I'm testing on the Genymotion emulator. On Nexus 7 4.4.4 800x1200, no text is displayed. On all other devices all good. Why is that?

UPD

Updated layout. It is also noticeable if view2 specifies android: layout_height = "match_parent", the text is displayed, but it does not take up the entire space of the parent layout, but only how much it needs.

UPD2

Updated layout. The height of view1 is not known in advance.

  • With such changes, everything depends on the size of view2 ("wrap_content"). If you specify it explicitly, the text will be visible. Most likely, if view2 is not empty, the text will also be displayed even with the "wrap_content" attribute. - Anton Shamanov
  • @AntonShamanov Yes, if you specify view2 height = match_parent, the text is displayed, but it takes along with view2 not the entire height of the parent. Indicate clearly does not work, it is not known in advance how much the image will occupy in height. - iamtihonov

6 answers 6

You should try the following: 1) Put RelativeLayout in LinearLayout and change in RelativeLayout android: layout_height:

 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal"> .......... </RelativeLayout> </LinearLayout> 

2) Change in ScrollView:

 android:layout_width="match_parent" android:layout_height="match_parent" 

3) Remove line from Linearlayout android: layout_alignBottom = "@ + id / view1"

 <LinearLayout android:id="@+id/parent_layout" android:layout_width="match_parent" android:layout_height="match_parent" -----android:layout_alignBottom="@+id/view1"------ android:layout_alignTop="@+id/view1" android:orientation="horizontal" android:background="@android:color/holo_blue_light"> 
  • If you remove android: layout_alignBottom, the layout will not know its borders. and then occupies only the size of the text on all devices - iamtihonov
  • Yes, exactly, you want the whole text to be visible, but at the same time you do not give it more space for placement. It drives me into a stupor. - Vitalii Obideiko
  • How not to give it? I know that the image will be large, so I give the text from it the height of all the space and horizontally half. - iamtihonov
  • on all devays, except the above, everything is ok - iamtihonov

Try changing the text color. On red, for example. The problem, perhaps, is that on this device the system background color is white.

  • text color is black, red think no better - iamtihonov

If the height of the LinearLayout is set equal to the view (150dp), the text starts to be displayed.

Slightly reworked code:

 <LinearLayout android:layout_width="match_parent" android:layout_height="150dp" android:layout_alignBottom="@+id/view" android:layout_alignTop="@+id/view" android:orientation="horizontal" android:background="@android:color/holo_blue_light"> <View android:id="@+id/view2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1"/> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:text="Текст" android:textColor="@android:color/background_dark" android:gravity="center" android:textSize="40sp"/> </LinearLayout> 
  • I indicated the height of 150dp for clarity, I thought it would be easier to understand. In fact, we do not know in advance how much height the picture will occupy. That is the value of view1, layout_height = "wrapContent" - iamtihonov

I will assume that the problem from UPD1 is solved by changing

 android:layout_height="wrap_content" 

u RelativeLayout on

 android:layout_height="match_parent" 
  • I do not know how this should help, but I still tried, it does not help. - iamtihonov

android: layout_height = "match_parent" in ScrollView

  • Not guessed, does not work - iamtihonov

Try TextView layout_height: wrap_content . I think he collapsed in height. So you can not see it.

  • Yes, you can do this and place it in an additional layout, for centering vertically, but parent_layout still does not occupy all the space vertically, but only how long does TextView occupy. - iamtihonov
  • Because of the parent View layout_height = "wrap_content", change it to match_parent - Inal Tuaev
  • parent_layout stands as you see match_parent, and additionally created match_parent. - iamtihonov