-2

I have two linearlayouts, each occupy the 50% of total space. Inside of them there are different views and I don't understand why the horizontalScrollView1 and the listView1 (look the ids) are not visible. The two views should expand to fill the space remaining in their parent. What I'am doing wrong?

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout        
       android:layout_height="0dp"
       android:layout_weight="1"
       android:layout_width="match_parent">
       <HorizontalScrollView
         android:id="@+id/header"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"/>
       <HorizontalScrollView
         android:layout_height="0dp"
         android:layout_weight="1"
         android:layout_width="match_parent"
         android:id="@+id/horizontalScrollView1">
         <ListView
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:id="@+id/list"/>
       </HorizontalScrollView>
    </LinearLayout>
    <LinearLayout         
      android:layout_height="0dp"
      android:layout_weight="1"
      android:layout_width="match_parent"  > 
      <TextView
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:text="Hello!!!" />
      <ListView
         android:layout_width="match_parent"
         android:layout_height="0dp"
         android:layout_weight="1"
         android:id="@+id/listView1"/>
    </LinearLayout>
 </LinearLayout>
Francesco
  • 50
  • 6
  • You forgot to add orientation type[android:orientation="vertical"] for both parent linear layouts which are having weight sum, check readyandroid answer for more clarification. – Ready Android Nov 23 '16 at 14:02

4 Answers4

3

You forgot to set android:orientation="vertical" to both LinearLayout of main LinearLayout. This way the child of LinearLayout are placed in vertical direction and will be visible.

R. Zagórski
  • 20,020
  • 5
  • 65
  • 90
0

You are using match_parent to your elements, so when one of them takes the full width the other one haven't got a place to draw. Set your inner elements width to wrap_content. And the orientations to the LinearLayout if you don't do it weight doesn't work.

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <LinearLayout        
       android:layout_height="0dp"
       android:layout_weight="1"
       android:layout_width="match_parent"
       android:orientation="vertical">
       <HorizontalScrollView
         android:id="@+id/header"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"/>
       <HorizontalScrollView
         android:layout_height="0dp"
         android:layout_weight="1"
         android:layout_width="wrap_content"
         android:id="@+id/horizontalScrollView1">
         <ListView
           android:layout_width="wrap_content"
           android:layout_height="match_parent"
           android:id="@+id/list"/>
       </HorizontalScrollView>
    </LinearLayout>
    <LinearLayout         
      android:layout_height="0dp"
      android:layout_weight="1"
      android:layout_width="match_parent"  
      android:orientation="vertical"> 
      <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Hello!!!" />
      <ListView
         android:layout_width="wrap_content"
         android:layout_height="0dp"
         android:layout_weight="1"
         android:id="@+id/listView1"/>
    </LinearLayout>
 </LinearLayout>
Alberto Méndez
  • 1,044
  • 14
  • 31
0

Check this out , I have coloured the required blocks also to differentiate.

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <LinearLayout
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:background="@color/accent"
            android:layout_width="match_parent">
            <HorizontalScrollView
                android:id="@+id/header"
                android:background="@color/primary"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>
            <HorizontalScrollView
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_width="match_parent"
                android:background="@color/black"
                android:id="@+id/horizontalScrollView1">
                <ListView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/list"/>
            </HorizontalScrollView>
        </LinearLayout>
        <LinearLayout
            android:orientation="horizontal"
            android:background="@color/green"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_width="match_parent"  >
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Hello!!!" />
            <ListView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:id="@+id/listView1"/>
        </LinearLayout>
    </LinearLayout>

Basically you have forgotten to add orientation=vertical at some places , plus need to specify android:layout_weight="1" for your both HorizontalScrollView.

Tasneem
  • 793
  • 8
  • 24
0

This is happening because you didn't mention weight for @+id/header horizontal scroll view. So it is taking full height of it's parent linear layout. And you forgot to add orientation type for both parent linear layouts.

You can check by this xml layout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <HorizontalScrollView
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

        <HorizontalScrollView
            android:id="@+id/horizontalScrollView1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

            <ListView
                android:id="@+id/list"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </HorizontalScrollView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Hello!!!" />

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    </LinearLayout>
</LinearLayout>
Ready Android
  • 3,529
  • 2
  • 26
  • 40