Question

This is a solution in order to add same space between views in the layout: make same space between button in linearlayout

But let say we have many items and we need to put them in HorizontalScrollView for handset devices.

<HorizontalScrollView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:layout_alignParentBottom="true" >

     <LinearLayout
        android:id="@+id/shareLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnRequestAPrescriptionRefill"
        android:layout_marginTop="10dp" >

        <Button
            android:id="@+id/btnFacebook"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/btn_facebook" />

        <View
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_weight="1" />

        ...

  </LinearLayout>
</HorizontalScrollView>

This solution works fine for handsets but in the tablet where we have a big screen size, the same space between buttons is not working. Buttons are just sticking together without no space that we created by:

<View
     android:layout_width="0dp"
     android:layout_height="50dp"
     android:layout_weight="1" />

Is there any solution?

Was it helpful?

Solution

A scroll view adapts it's size to its content view (the linear layout) but when the screen is large enough you want it the other way around, you want the content view to adapt its size to the scroll view. This is a little contradictory.

The only way to do this is specifying a minWidth property for your LinearLayout.

android:minWidth="200dp" 

This is a pain in the butt because you probably need to set it at runtime, or have many versions of your XML for different screen resolutions.

Maybe another approach for large screen resolutions would be providing a different XML without the scrollview.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top