[英]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. 我尝试将width设置为wrap_content
, 一些固定值和match_parent
但是所有这些都给了我相同的结果。
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>
You should not use such a design, you should use a tab bar and link to the action bar of Android. 您不应使用这种设计,而应使用标签栏并链接到Android的操作栏。
http://android-developers.blogspot.fr/2011/04/customizing-action-bar.html http://android-developers.blogspot.fr/2011/04/customizing-action-bar.html
Just set linearlayout's orientation 只需设置linearlayout的方向
android:orientation="horizontal"
and give this two parameters for all buttons 并为所有按钮提供这两个参数
android:layout_widht="0dp"
android:layout_weight="1"
Now all buttons will have equal width. 现在所有按钮的宽度相等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.