Android 让按钮大小相同
我的布局代码如下:Android 让按钮大小相同,android,layout,Android,Layout,我的布局代码如下: <LinearLayout android:id="@+id/linearLayout2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_left"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="Phone Files" />
<TextView
android:id="@+id/list_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:text="Photos"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/btn_right"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="Save" />
</LinearLayout>
如何让btn_left和btn_right具有相同的大小?尝试将
android:weightSum=“2.5”
作为属性添加到LinearLayout标记中,并将所有三个小部件的布局宽度值更改为android:layou width=“0dip”
如果重量不再重要,只需从布局中删除重量,并为这两个按钮提供相同的大小即可。
见下文:
编辑:
在String.xml文件中创建字符串
如下所示:
Phone“\n”文件
然后把下面的代码,它会显示两行文字的按钮
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_left"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/button_name"/>
<TextView
android:id="@+id/list_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:text="Photos"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/btn_right"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Save" />
</LinearLayout>
希望它能像你想的那样工作。
谢谢
享受。编辑后,完全忽略了将权重设置为填充父对象的事实,尝试将属性“布局权重”中的权重更改为0dip“0dip”无法转换为floatWow。。对不起,是版面宽度,不是版面重量。。一次尝试做太多的事情会使按钮变得非常宽,但我不想要它。如果没有任何更重要的东西,那么为什么你不给两个按钮相同的大小?我的意思是android:width=“50dp”这样。我想知道linearlayout是否使用android:layout\u alignParentLeft=“true”android:layout\u alignParentTop=“true”但我希望左侧按钮文本显示2行,右侧按钮文本仅显示1行。好的,我已经解决了您的问题。请等待我编辑的答案。@brian:查看更新的答案。@brian:如果你得到了解决方案,那么你可以接受答案,这样可以帮助他人。并放弃投票,给出所有可接受的答案。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center_vertical"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_left"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/button_name"/>
<TextView
android:id="@+id/list_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="center_horizontal"
android:text="Photos"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/btn_right"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Save" />
</LinearLayout>