简体   繁体   English

如何在Android中自定义按钮栏?

[英]How to customize buttonbar in android?

I made a button bar that contains some buttons in it, I faced two problems: 我制作了一个包含一些按钮的按钮栏 ,我遇到了两个问题:

The first one is that when the buttons fill the width of the screen the new ones begin to behave wrongly: see from here 第一个是当按钮填满屏幕宽度时,新按钮开始出现错误行为: 从此处查看

I had try setting width to wrap_content and some fixed values but both didn't work. 我尝试将width设置为wrap_content一些固定值,但是都没有用。

The second one is that I want the buttons to appear like if they are merged in the buttonbar and only separated by simple lines, Like That . 第二个是我希望按钮看起来像是它们在按钮栏中合并时一样,并且仅由简单的行( 如Like)分隔。

here's my xml: 这是我的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>

1) What Layout do you use? 1)您使用什么布局?

Try to use LinearLayout and set each item layout_weihgt = 1 in XML. 尝试使用LinearLayout并在XML中设置每个项目layout_weihgt = 1 Also item's width must be match_parent . 此外,商品的宽度必须为match_parent

2) You must create custom layout for buttons. 2)您必须为按钮创建自定义布局。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM