我的布局代码如下:
<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大小一致?
发布于 2012-01-06 12:24:12
如果没有更重要的权重,那么只需从您的布局中删除权重,并为这两个按钮提供相同的大小。如下所示:
编辑:
在string.xml文件中创建字符串,如下所示:
<string name="button_name">Phone "\n" Files</string>然后放入下面的代码,它将显示带有两行文本的Button。
<?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>希望它能像你想要的那样工作。谢谢。好好享受吧。
发布于 2012-01-06 09:12:45
尝试将android:weightSum="2.5"作为属性添加到LinearLayout标签中,并将所有三个小部件的layout_width值更改为android:layout_width="0dip"
https://stackoverflow.com/questions/8752202
复制相似问题