1

There is the following code:

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="0.9"
            android:gravity="center"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/activityEvaluationYesterdayValueDisplay"
                android:layout_width="15dip"
                android:layout_height="wrap_content"
                android:text="0"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textStyle="bold" />

            <com.ulnda.mypsych.views.VerticalSeekBar
                android:id="@+id/activityEvaluationYesterdayValue"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:max="10"
                android:progress="0" />
        </LinearLayout>

Now I need to change LinearLayout to RelativeLayout. If I do it then RelativeLayout fill the whole screen, and it's bad. I understand that RelativeLayout doesn't use layout_weight for its work. Please, tell me, how can I fix it? I've tried to make LinearLayout wrapper for RelativeLayout, but it doesn't help.

UPDATE:

<?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="0dip"
        android:layout_weight="0.6"
        android:orientation="vertical" >

        <RelativeLayout
            android:background="#000000"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </RelativeLayout>

    </LinearLayout>

</LinearLayout>
UPDATE 2: FUll code
<?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" >

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="0.5" >

            <LinearLayout
                android:weightSum="1.0"
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="0.33"
                android:orientation="vertical" >

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="0.9">

                    <TextView
                        android:id="@+id/activityEvaluationYesterdayValueDisplay"
                        android:layout_width="15dip"
                        android:layout_height="wrap_content"
                        android:text="0"
                        android:layout_centerVertical="true"
                        android:layout_toLeftOf="@+id/activityEvaluationYesterdayValue"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textStyle="bold" />

                    <com.ulnda.mypsych.views.VerticalSeekBar
                        android:id="@+id/activityEvaluationYesterdayValue"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:layout_centerInParent="true"
                        android:max="10"
                        android:progress="0" />
                </RelativeLayout>

                <TextView
                    android:id="@+id/TextView05"
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="0.1"
                    android:gravity="center"
                    android:text="Yesterday"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textStyle="bold" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="0.33"
                android:orientation="vertical" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="0.9"
                    android:gravity="center"
                    android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/activityEvaluationTodayValueDisplay"
                        android:layout_width="20dip"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text="0"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textStyle="bold" />

                    <com.ulnda.mypsych.views.VerticalSeekBar
                        android:id="@+id/activityEvaluationTodayValue"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:max="10"
                        android:progress="0" />
                </LinearLayout>

                <TextView
                    android:id="@+id/TextView03"
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="0.1"
                    android:gravity="center"
                    android:text="Today"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textStyle="bold" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="0.33"
                android:orientation="vertical" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="0.9"
                    android:gravity="center"
                    android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/activityEvaluationTomorrowValueDisplay"
                        android:layout_width="20dip"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text="0"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textStyle="bold" />

                    <com.ulnda.mypsych.views.VerticalSeekBar
                        android:id="@+id/activityEvaluationTomorrowValue"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:max="10"
                        android:progress="0" />
                </LinearLayout>

                <TextView
                    android:id="@+id/TextView02"
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="0.1"
                    android:gravity="center"
                    android:text="Tomorrow"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textStyle="bold" />
            </LinearLayout>
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="wrap_content"
            android:layout_height="0dip"
            android:layout_weight="0.5" >

            <LinearLayout
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="0.33"
                android:orientation="vertical" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="0.9"
                    android:gravity="center"
                    android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/activityEvaluationEnergyValueDisplay"
                        android:layout_width="20dip"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text="0"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textStyle="bold" />

                    <com.ulnda.mypsych.views.VerticalSeekBar
                        android:id="@+id/activityEvaluationEnergyValue"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:max="10"
                        android:progress="0" />
                </LinearLayout>

                <TextView
                    android:id="@+id/TextView11"
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="0.1"
                    android:gravity="center"
                    android:text="Energy"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textStyle="bold" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="0.33"
                android:orientation="vertical" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="0.9"
                    android:gravity="center"
                    android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/activityEvaluationWeatherValueDisplay"
                        android:layout_width="20dip"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text="0"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textStyle="bold" />

                    <com.ulnda.mypsych.views.VerticalSeekBar
                        android:id="@+id/activityEvaluationWeatherValue"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:max="10"
                        android:progress="0" />
                </LinearLayout>

                <TextView
                    android:id="@+id/TextView09"
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="0.1"
                    android:gravity="center"
                    android:text="Weather"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textStyle="bold" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dip"
                android:layout_height="match_parent"
                android:layout_weight="0.33"
                android:orientation="vertical" >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="0.9"
                    android:gravity="center"
                    android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/activityEvaluationHoursSleptValueDisplay"
                        android:layout_width="20dip"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:text="0"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textStyle="bold" />

                    <com.ulnda.mypsych.views.VerticalSeekBar
                        android:id="@+id/activityEvaluationHoursSleptValue"
                        android:layout_width="wrap_content"
                        android:layout_height="match_parent"
                        android:max="10"
                        android:progress="0" />
                </LinearLayout>

                <TextView
                    android:id="@+id/TextView07"
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="0.1"
                    android:gravity="center"
                    android:text="Hours Slept"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textStyle="bold" />
            </LinearLayout>
        </TableRow>
    </TableLayout>

</LinearLayout>

Why RelativeLayout fill whole screen, not 0.6 ?

user1841247
  • 413
  • 1
  • 7
  • 20

2 Answers2

6

android:layout_weight makes sense only for LinearLayout. Lint should aware you about with a warning

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • But how can I do my task? I need to use RelativeLayout in order to align my VerticalSeekBar by center and TextView by left of VerticalSeekBar – user1841247 Jan 16 '13 at 13:32
  • RelativeLayout has lot of methods to place things. For instance layout_toLeftOf Check the documentation – Blackbelt Jan 16 '13 at 13:35
  • I know it, but I can't just use RelativeLayout because it fill all screen space. Please, tell me, how can I fix it? – user1841247 Jan 16 '13 at 13:39
  • it fills the screen space because for every element you declare inside it you should provided its position – Blackbelt Jan 16 '13 at 13:40
  • there is nothing inside the RelativeLayout. Then with match_parent you are asking to fill all the available space. Maybe you want to give to "wrap_content" a try? – Blackbelt Jan 16 '13 at 13:47
  • It hasn't help. Please, edit my code, may be I don't understand you quietly. – user1841247 Jan 16 '13 at 13:54
1

RelativeLayout is the only one child who has layout_weight attribute so you should also specify weightSum:

<?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"
    android:weightSum="1">

    <RelativeLayout
        android:background="#ff0000"
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.6">

    </RelativeLayout>
</LinearLayout>
Vladimir Mironov
  • 30,514
  • 3
  • 65
  • 62
  • Thank you! Please, tell me, where can I read about weightSum? I don't know anything about it. – user1841247 Jan 16 '13 at 13:59
  • If your first code works for `LinearLayout` it should also work for `RelativeLayout` as well. You can read about `weightSum` here http://stackoverflow.com/questions/7452741/what-is-androidweightsum-in-android-and-how-does-it-work – Vladimir Mironov Jan 16 '13 at 14:09
  • Please, look at my second update. This code doesn't work properly. I've just change LinearLayout to RelativeLayout and add some attributes to childs of RelativeLayout. Please, look at this. – user1841247 Jan 16 '13 at 14:16