androidbuttonbuttonbar

Buttons strange behavior in a Buttonbar in Android


I create a button bar with some buttons,the problem i have here is when the buttons fill the width of the screen the new ones begin to shrink: see from here

I had try setting width to wrap_content, some fixed values, and match_parent but all of that gave me the same result.

here's my xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Home" >

    <LinearLayout
        android:id="@+id/grid1"
        android:layout_width="875dp"
        android:layout_height="500dp"
        android:layout_centerInParent="true"
        android:background="@android:color/darker_gray"
        android:orientation="vertical" >
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:gravity="top"
        style="@android:style/ButtonBar" >

        <Button
            android:id="@+id/Main"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="@string/main"
            android:layout_weight="1"/>

        <Button
            android:id="@+id/HomeView"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_toRightOf="@+id/Main"
            android:text="@string/homeview" />

        <Button
            android:id="@+id/Lighting"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_toRightOf="@+id/HomeView"
            android:text="@string/lighting" />

        <Button
            android:id="@+id/A.C."
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_toRightOf="@+id/Lighting"
            android:text="@string/ac" />

        <Button
            android:id="@+id/Profiles"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_toRightOf="@+id/A.C."
            android:text="@string/profiles" />

        <Button
            android:id="@+id/Movies"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_toRightOf="@+id/Profiles"
            android:text="@string/movies" />

        <Button
            android:id="@+id/Music"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_toRightOf="@+id/Movies"
            android:text="@string/music" />

        <Button
            android:id="@+id/TVShows"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_toRightOf="@+id/Music"
            android:text="@string/tvshows" />

        <Button
            android:id="@+id/Remote"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_toRightOf="@+id/TVShows"
            android:text="@string/remote" />
    </LinearLayout>

</RelativeLayout>

Solution

  • You should not use such a design, you should use a tab bar and link to the action bar of Android.

    http://android-developers.blogspot.fr/2011/04/customizing-action-bar.html