簡體   English   中英

如何在Android中自定義按鈕欄?

[英]How to customize buttonbar in android?

我制作了一個包含一些按鈕的按鈕欄 ,我遇到了兩個問題:

第一個是當按鈕填滿屏幕寬度時,新按鈕開始出現錯誤行為: 從此處查看

我嘗試將width設置為wrap_content一些固定值,但是都沒有用。

第二個是我希望按鈕看起來像是它們在按鈕欄中合並時一樣,並且僅由簡單的行( 如Like)分隔。

這是我的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)您使用什么布局?

嘗試使用LinearLayout並在XML中設置每個項目layout_weihgt = 1 此外,商品的寬度必須為match_parent

2)您必須為按鈕創建自定義布局。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM