首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >让按钮具有相同大小

让按钮具有相同大小
EN

Stack Overflow用户
提问于 2012-01-06 09:10:37
回答 2查看 541关注 0票数 0

我的布局代码如下:

代码语言:javascript
复制
    <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大小一致?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-01-06 12:24:12

如果没有更重要的权重,那么只需从您的布局中删除权重,并为这两个按钮提供相同的大小。如下所示:

编辑:

在string.xml文件中创建字符串,如下所示:

代码语言:javascript
复制
 <string name="button_name">Phone "\n" Files</string>

然后放入下面的代码,它将显示带有两行文本的Button。

代码语言:javascript
复制
<?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>

希望它能像你想要的那样工作。谢谢。好好享受吧。

票数 1
EN

Stack Overflow用户

发布于 2012-01-06 09:12:45

尝试将android:weightSum="2.5"作为属性添加到LinearLayout标签中,并将所有三个小部件的layout_width值更改为android:layout_width="0dip"

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8752202

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档