Noor
Noor

Reputation: 20150

Linearlayout not displaying anything

I using android:layout_weight to limit the size of my view but now I'm not seeing anything on the screen. Here are the codes:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout 
                android:layout_width="0dp" 
                android:layout_height="wrap_content" 
                android:layout_weight="2" 
                android:orientation="vertical"/>
   <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">



            <LinearLayout 
                android:layout_width="0dp" 
                             android:layout_height="wrap_content" 
                             android:layout_weight="3" 
                android:orientation="vertical"
               >

Upvotes: 0

Views: 86

Answers (6)

Hareshkumar Chhelana
Hareshkumar Chhelana

Reputation: 24848

// try this way hope this will help you...
<?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_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.25"
        android:gravity="center"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="0.25 % Area"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.75"
        android:gravity="center">
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="0.75 % Area"/>
            </LinearLayout>
        </ScrollView>
    </LinearLayout>
</LinearLayout>

Upvotes: 1

Hashir Sheikh
Hashir Sheikh

Reputation: 1821

This should be helpful

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 android:weightSum="5">

<LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_weight="2" 
        android:orientation="vertical"/>
<ScrollView
    android:layout_width="match_parent"
    android:layout_weight="3" 
    android:layout_height="0dp">

    <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"
       >

Upvotes: 1

Silambarasan Poonguti
Silambarasan Poonguti

Reputation: 9442

You should use weightSum property in your parent Linear layout, like android:weightSum="number of child"

Upvotes: 1

Arun Antoney
Arun Antoney

Reputation: 4382

try this, first u need to give the weight sum in main linear layout. Also change 0dp to 0 dip

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5">

<LinearLayout 
            android:layout_width="0dip" 
            android:layout_height="wrap_content" 
            android:layout_weight="2" 
            android:orientation="vertical"/>
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <LinearLayout 
            android:layout_width="0dip" 
                         android:layout_height="wrap_content" 
                         android:layout_weight="3" 
            android:orientation="vertical"
           >

Upvotes: 1

Rashad
Rashad

Reputation: 11197

Try this:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout 
                android:layout_width="100dp" 
                android:layout_height="wrap_content" 
                android:layout_weight="2" 
                android:orientation="vertical"/>
                <ScrollView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content">

                     <LinearLayout 
                         android:layout_width="50dp" 
                         android:layout_height="wrap_content" 
                         android:layout_weight="3" 
                         android:orientation="vertical"
                      >

This will help you to see something. Change the width according to your requirement.

Upvotes: 1

Zohra Khan
Zohra Khan

Reputation: 5302

Setting android:layout_width="0dp" will make this layout invisible. Change it to wrap_content or something else.

Upvotes: 0

Related Questions