1. Are you ready for the Galaxy S20? Here is everything we know so far!

How to make a layout just fits the width when it's in a HorizonrtalScrollView

Discussion in 'Android Development' started by MuhammedRefaat, Dec 31, 2013.

  1. MuhammedRefaat

    Thread Starter

    I have a horizontal LinearLayout that contains bunch of vertical LinearLayouts , each one of these vertical Layouts supposed to fit only 25% of the horizontal layout, so it can only contains four ones, so, i want to add a HorizontalViewScroll to contain the rest of the vertical layouts when it's number is more than four,
    i set the WeightSum of the horizontal layout as four so that any vertical layout will take a weight as one, and that will make it fits only 25% of the horizontal layout. everything is OK before adding the HorizontalViewScroll , consider the following figure (the vertical layouts is the Green colored):


    [​IMG]


    But when adding the HorizontalViewScroll :


    [​IMG]


    I considered setting the horizontal layout as WrapContent and FillParent but the same result, although the same when setting HorizontalViewScroll as WrapContent and FillParent .


    XML code:


    [HIGH]
    <HorizontalScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:eek:rientation="horizontal"
    android:weightSum="4" >

    <LinearLayout
    android:id="@+id/innerVer1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:eek:rientation="vertical"
    android:weightSum="1" >

    <LinearLayout
    android:id="@+id/icon1"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="15dp"
    android:layout_weight="0.5"
    android:background="@drawable/ac_overlay"
    android:eek:rientation="horizontal"
    android:tag="normal" >
    </LinearLayout>

    <LinearLayout
    android:id="@+id/icon2"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="15dp"
    android:layout_weight="0.5"
    android:background="@drawable/ac_overlay"
    android:eek:rientation="horizontal"
    android:tag="normal" >
    </LinearLayout>
    </LinearLayout>
    <LinearLayout
    android:id="@+id/innerVer1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:eek:rientation="vertical"
    android:weightSum="1" >

    <LinearLayout
    android:id="@+id/icon1"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="15dp"
    android:layout_weight="0.5"
    android:background="@drawable/ac_overlay"
    android:eek:rientation="horizontal"
    android:tag="normal" >
    </LinearLayout>

    <LinearLayout
    android:id="@+id/icon2"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="15dp"
    android:layout_weight="0.5"
    android:background="@drawable/ac_overlay"
    android:eek:rientation="horizontal"
    android:tag="normal" >
    </LinearLayout>
    </LinearLayout>
    </LinearLayout>
    </HorizontalScrollView>[/HIGH]
     


Loading...
Similar Threads - layout fits width
  1. bjourine stekarfield
    Replies:
    0
    Views:
    380
  2. sariDon2
    Replies:
    0
    Views:
    585
  3. workbench
    Replies:
    3
    Views:
    313
  4. Mahmudul001
    Replies:
    0
    Views:
    639
  5. beez zaen
    Replies:
    0
    Views:
    454
  6. OM2
    Replies:
    2
    Views:
    487
  7. mahaju
    Replies:
    0
    Views:
    505
  8. umtblbl
    Replies:
    1
    Views:
    384
  9. Aznoh
    Replies:
    0
    Views:
    374
  10. Korsholm
    Replies:
    0
    Views:
    304

Share This Page

Loading...