dimanche 3 mai 2015

Maintain fixed ration between LinearLayou and TableLayout height

In the below code, I designed so that linearLayout2 and tableLayout2 should have 1:2 height ratio. linearLayout2 contains 1 imageview and 1 table layout with 4 table rows whereas tableLayout2 contains 8 table rows.

Normally this setup works fine. But if I load a longer image in imageview1, the setup gets messed up with linearLayout2 becomes very long (same size as imageview1), but tableLayout2 srinks to minimum height.

How can I make sure to maintain same 1:2 ratio all the time?

Thanks,

<RelativeLayout 
    xmlns:android="http://ift.tt/nIICcg"
    xmlns:tools="http://ift.tt/LrGmb4"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

  <ScrollView
      android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true" >
      <LinearLayout
          android:id="@+id/linearLayout1"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" >
          <LinearLayout
              android:id="@+id/linearLayout2"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="0dp"
              android:layout_weight="0.33" >
              <ImageView 
                  android:id="@+id/imageview1"
                  android:scaleType="centerInside"
                  android:adjustViewBounds="true"
                  android:layout_width="wrap_content"
                  android:layout_height="fill_parent" />

              <TableLayout
                      android:id="@+id/tableLayout1"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:stretchColumns="1" >
                  <TableRow
                      android:layout_width="wrap_content"
                      android:layout_height="0dp"
                      android:layout_weight="1" >

..........................................................................
.............................. 4 such TableRow ...........................
..........................................................................

              </TableLayout>    
          </LinearLayout>
          <TableLayout
              android:id="@+id/tableLayout2"
              android:layout_width="fill_parent"
              android:layout_height="0dp"
              android:layout_weight="0.67"
              android:stretchColumns="1,3" >

              <TableRow
                  android:layout_width="wrap_content"
                  android:layout_height="0dp"
                  android:layout_weight="1">

..........................................................................
.............................. 8 such TableRow ...........................
..........................................................................                

              </TableRow>
          </TableLayout>
      </LinearLayout>
    </ScrollView>
</RelativeLayout>

Aucun commentaire:

Enregistrer un commentaire