首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android-Layout: RelativeLayout可以自动调整编辑文本字段的大小吗?

Android-Layout: RelativeLayout可以自动调整编辑文本字段的大小吗?
EN

Stack Overflow用户
提问于 2012-11-19 22:58:45
回答 4查看 1.7K关注 0票数 0

我正在尝试了解相对布局是如何工作的。我知道如果我使用LinearLayout,我会有两个编辑文本字段,并排,水平。使用'weight‘将使edittext字段仅根据屏幕大小调整大小。(它可能看起来很奇怪,但它会做到的)。

我知道线性布局不是最有效的。我可以使用相对布局并具有相同的效果吗?我不想指定大小,我只想扩展edittext。

使用这样的线性布局,xml看起来会是什么样子?

谢谢你,迈克

EN

回答 4

Stack Overflow用户

发布于 2012-11-20 07:43:06

我能看到的一件事是大多数android开发人员都在布局上花费了毕生精力。

看起来你可以用RelativeLayouts做我想做的事情,但只能用2..at的倍数,至少到目前为止我发现的是这样。在按钮中心,两个按钮放在同一行上,每个按钮占据大约半个屏幕。如果没有按钮中心,它们会相互重叠。不知道这是否值得。

希望这能对大家有所帮助,谢谢大家!

代码语言:javascript
复制
<View android:id="@+id/button_center" android:layout_width="0dp"
    android:layout_height="0dp" android:layout_centerHorizontal="true" />

<Button android:id="@+id/btnButton1" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:text="Button 1" 
    android:layout_toLeftOf="@+id/button_center"/>

<Button android:id="@+id/btnButton2" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:text="Button 2"
    android:layout_toRightOf="@+id/button_center" />

票数 1
EN

Stack Overflow用户

发布于 2012-11-19 23:01:37

我认为这可以使用alignLeft/alignRight来完成,但不幸的是,似乎需要嵌套的LinearLayout。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true" >

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="Left" >

            <requestFocus />
        </EditText>

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:text="Right" />
    </LinearLayout>

</RelativeLayout>
票数 0
EN

Stack Overflow用户

发布于 2012-11-19 23:04:56

如果您只是在EditText字段中使用width="fill_parent“和height="fill_parent”(可能还会使用一些填充或边距)呢?

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

https://stackoverflow.com/questions/13456350

复制
相关文章

相似问题

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