1

I want to make three layout with same height

  • I want all three Linear Layout in scrollview
  • Each Linear layout are orientation horizontal and have two componants ImageView and Textview
  • In all Three layout textview have diffrent Lines of text
  • Now I want each layout size same if text line are less then also enter image description here

In Image you can see exact problem which I faced I want Orange row height to blue row and yellow row. But you see in yellow row height not same

My xml code is below

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




<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.4"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/frag_home_iv"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:src="@android:drawable/sym_def_app_icon" />
</LinearLayout>
 <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="0.6"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true">


        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:weightSum="1">


            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_gravity="center"
                android:layout_weight="0.26"
                android:background="@color/colorAccent"
                android:orientation="vertical"
                android:padding="@dimen/padding_5dp">

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="horizontal"
                    android:padding="@dimen/padding_3dp"
                    android:weightSum="1">

                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="fill_parent"
                        android:layout_weight="0.33"
                        android:padding="@dimen/margin_5dp"

                        android:src="@android:drawable/sym_def_app_icon" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_weight="0.67"

                        android:text="asdsdgvsfdagsmdknsdjkcjkcbvuhsdjkfnh sjvnfslbvhsdfglsfvbfvufvgl,fgklcm,.vngkg.f,gm kjfbkjvn,dfmgkjhfgasfgkksfgmkdjfbndfbjkdnh,.dghlkgd"
                        android:textColor="@color/BlackColor" />


                </LinearLayout>

            </LinearLayout>
<LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_gravity="center"
                android:layout_weight="0.74"
                android:orientation="vertical"
                android:weightSum="1"

                >

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="0dp"
                    android:layout_marginTop="@dimen/margin_8dp"
                    android:layout_weight="1"
                    android:background="@color/HomeListItem2"
                    android:orientation="horizontal"
                    android:padding="@dimen/padding_3dp"
                    android:weightSum="1">

                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="0.3"

                        android:src="@android:drawable/sym_def_app_icon" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_weight="0.7"
                        android:text="sanf,cbjkdbvjdkfnashdfkjnsjabsjdmfnvshbgvbvvbuhfbvgkdfbuhvdfgjkfbghsjkvkcbfgmbfhuvgbfgvfsjghsjvknfvfngvbfuygbvjkakhsdjhgvhfjnuyvhjfdnjgnifhg"
                        android:textColor="@color/WhiteColor" />

                </LinearLayout>


                <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="0dp"
                    android:layout_marginTop="@dimen/margin_8dp"
                    android:layout_weight="1"
                    android:background="@color/HomeListItem3"

                    android:orientation="horizontal"
                    android:padding="@dimen/padding_3dp"
                    android:weightSum="1">

                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="0.3"
                        android:src="@android:drawable/sym_def_app_icon" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_weight="0.7"
                        android:padding="@dimen/padding_10dp"

                        android:text="awofkldjvugifklgmfhklmfgtnemylktmfedghquafrgmketo"

                        android:textColor="@color/WhiteColor" />

                </LinearLayout>
 <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="0dp"
                    android:layout_marginTop="@dimen/margin_8dp"
                    android:layout_weight="1"
                    android:background="@color/HomeListItem4"
                    android:orientation="horizontal"
                    android:padding="@dimen/padding_3dp"
                    android:weightSum="1">

                    <ImageView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="0.3"
                        android:padding="@dimen/margin_5dp"
                        android:src="@android:drawable/sym_def_app_icon" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_weight="0.7"
                        android:text="flkghoijhfnigksngaugjknnguhfbjvncuyvgijfgyhfnvjfdnvjkayfgnkdfbvhjcvndfighfdmndfiuhvhnfidjghiudfhguifdhgiuhafgijhnfaiifjgnu8idfhbjkfndbguy"
                        android:textColor="@color/WhiteColor" />

                </LinearLayout>


            </LinearLayout>

        </LinearLayout>


    </ScrollView>
</LinearLayout>

Vishal Thakkar
  • 2,117
  • 2
  • 16
  • 33
  • Use weight [here](http://stackoverflow.com/questions/3995825/what-does-androidlayout-weight-mean) system to tell their proportions (1/1/1), or (2/1/1/1), depending on the view hierarchy there – Bonatti Jan 12 '16 at 10:32

3 Answers3

0

apply this property in your all three linearLayout

android:layout_weight="1"

android:layout_height="0dp"

nikk
  • 407
  • 3
  • 7
0

There are no constraints in Android like yours. But you can achieve same height by using layout_weight.

Initially set all your weight to 1 and height to 0dp . For example:

<?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:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:orientation="vertical" >
<Button
        android:layout_width="100dp"
        android:layout_height="0dp"
        android:layout_gravity="right"
        android:text="@string/send" 
 layout_weight="1"/>
    <Button
        android:layout_width="100dp"
        android:layout_height="0dp"
        android:layout_gravity="right"
        android:text="@string/send1" 
 layout_weight="1"/>
    <Button
        android:layout_width="100dp"
        android:layout_height="0dp"
        android:layout_gravity="right"
        android:text="@string/send2"
 layout_weight="1" />
</LinearLayout>

EDIT 1:

Sample ImageSample

Amsheer
  • 7,046
  • 8
  • 47
  • 81
0
<ScrollView .....>
    <LinearLayout android:orientation="vertical"
        android:height="match_parent"
        android:width="match_parent"
       ...>

       <LinearLayout
           android:width="match_parent"
           android:height="0dp"
           android:weight="1"
           ..... >
       </LinearLayout>

       <LinearLayout
           android:width="match_parent"
           android:height="0dp"
           android:weight="1"
           ..... >
       </LinearLayout>

       <LinearLayout
           android:width="match_parent"
           android:height="0dp"
           android:weight="1"
           ..... >
       </LinearLayout>

    </LinearLayout>
</ScrollView>
hehe
  • 1,294
  • 13
  • 26