首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UI设计问题

UI设计问题
EN

Stack Overflow用户
提问于 2018-09-28 22:59:21
回答 1查看 39关注 0票数 0

我是Android的新手。我正在为一个注册表创建一个布局。我使用基本容器作为相对布局。内部相对布局,我是保持线性布局容器,然后在这里面的所有组件的注册表。

但是在下垂两个编辑文本字段后,我可以看到这两个编辑文本字段彼此重叠,并且它作为一个可见,并且在线性容器中也向中心移动。希望大家都明白。我需要一个接一个的组件。帮助?

代码语言:javascript
复制
 <?xml version="1.0" encoding="utf-8"?>
<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:background="@color/colorAccent"
    >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="30dp"
            android:background="@drawable/l_border"
            android:padding="30dp"
            >

            <EditText
                android:id="@+id/txtMobile"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:background="@drawable/ll_border"
                android:backgroundTint="@color/colorAccent"
                android:hint="Enter Name"
                android:padding="10dp"
                android:textColorHint="@color/colorBlack" />

            <EditText
                android:id="@+id/txtName"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:background="@drawable/ll_border"
                android:backgroundTint="@color/colorAccent"
                android:hint="Enter Mobile"
                android:padding="10dp"
                android:textColorHint="@color/colorBlack" />

        </LinearLayout>

</RelativeLayout>

[

EN

回答 1

Stack Overflow用户

发布于 2018-09-28 23:05:21

首先,除非您想在内部LinearLayout上添加一些内容,否则将其嵌套在RelativeLayout中是没有意义的。

其次,您的内部LinearLayout没有设置方向,因此默认情况下设置为horizontal,这意味着第一个编辑文本(layout_width="match_parent")将从屏幕上推出第二个EditText。

如果您将内部LinearLayot的方向设置为“垂直”,您将能够同时看到这两个字段。

如果要水平放置这两个编辑文本,请在这两个文本字段上设置"layout_width"="0; "weight"="1。或者,您可以尝试RelativeLayout定位。

更新--由@petey建议

这里有一种实现你想要的东西的方法:

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"  // this view is kind of pointless
android:background="@color/colorAccent"> 
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="30dp"
    android:background="@drawable/l_border"
    android:padding="30dp">

    <EditText
        android:id="@+id/txtMobile"
        android:layout_width="0dp" // NOTICE THIS
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_weight="1" // // NOTICE THIS
        android:background="@drawable/ll_border"
        android:backgroundTint="@color/colorAccent"
        android:hint="Enter Name"
        android:padding="10dp"
        android:textColorHint="@color/colorBlack" />

    <EditText
        android:id="@+id/txtName"
        android:layout_width="0dp" // NOTICE THIS
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_weight="1" // NOTICE THIS
        android:background="@drawable/ll_border"
        android:backgroundTint="@color/colorAccent"
        android:hint="Enter Mobile"
        android:padding="10dp"
        android:textColorHint="@color/colorBlack" />

</LinearLayout>

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

https://stackoverflow.com/questions/52558000

复制
相关文章

相似问题

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