Question

I have a RelativeLayout styled as a ButtonBar and contained in a HorizontalScrollView, this layout is a ssigned to a fixed height in order to be controlled but that make it looks giant in small screen devices,

for ex, in a 10' device:

enter image description here

And in a 3.7' device:

enter image description here

And here's my XML code:

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tool"
    android:id="@+id/horizontalScrollView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true" >
    <RelativeLayout
        android:id= "@+id/buttobbar"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:gravity="top"
        style="@android:style/ButtonBar"
        android:background="@drawable/released" >

        <Button
            android:id="@+id/Main"
            android:layout_width="120dp"
            android:layout_height="60dp"
            android:background="@android:color/transparent"
            android:textColor="@android:color/white"
            android:textStyle="bold"
            android:text="@string/main"/>

        <View 
            android:id="@+id/separator"
            android:layout_height="fill_parent"
            android:layout_toRightOf="@+id/Main"
            android:layout_width="1px"
            android:background="@drawable/separators"/>

        <Button
            android:id="@+id/HomeView"
            android:layout_width="120dp"
            android:layout_height="60dp"
            android:background="@android:color/transparent"
            android:textColor="@android:color/white"
            android:textStyle="bold"
            android:layout_toRightOf="@+id/Main"
            android:text="@string/homeview" />

         <View 
            android:id="@+id/separator"
            android:layout_height="fill_parent"
            android:layout_toRightOf="@+id/HomeView"
            android:layout_width="1px"
            android:background="@drawable/separators"/>

          .
          .
          . <!-- after 7 other buttons separated with views --!>
    </RelativeLayout>
    </HorizontalScrollView>
Was it helpful?

Solution 2

Adding weight would be a best option: Try this:

android:weightSum="1"

and divide this weight sum to the butons as follows:

android:layout_weight=0.5

OTHER TIPS

take linear layout at the place of relative layout and u dont have to give absolute value of layout_width just use android:layout_weight and give weight to all button from this it will automatically adjust on all screen whatever it will be i think it will help u

Assign weight to the layout(Linear layout) by just writing the following code:

 android:weightSum="1"(can vary,according to your requirement)

and divide this weight sum to the butons as follows:

android:layout_weight=0.5

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