首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用android布局

使用android布局
EN

Stack Overflow用户
提问于 2018-06-19 08:57:47
回答 3查看 69关注 0票数 1

我是android的新手,定位元素与web的定位元素有很大不同。

所以我想做的是:

代码语言:javascript
复制
Login: ______  
Password: _____  

通过将linearLayout设置为垂直方向,我可以得到以下结果:

代码语言:javascript
复制
Login:  
__  
Password:  
__

或者这样,水平方向:

代码语言:javascript
复制
Login:_____Password:_____  

我如何将其混合在一起并实现我所需要的?

当前代码:

代码语言:javascript
复制
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/mainActivity"
        tools:context=".MainActivity">

        <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Login:"
        android:textSize="14pt"/>

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:id="@+id/loginText"/>

        <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Senha:"
        android:textSize="14pt"/>  

<EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:id="@+id/passText"/>


    </LinearLayout>
EN

回答 3

Stack Overflow用户

发布于 2018-06-19 09:01:51

嵌套您的线性布局。有一个垂直的顶层线性布局,里面有两个水平的线性布局,每一个都做你输出的一行。

票数 2
EN

Stack Overflow用户

发布于 2018-06-19 09:24:34

通常在移动设备上,你不需要像在web上那样使用标签。EditText上的setHint应该足以让用户清楚地了解字段的用途。

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:id="@+id/mainActivity"
    tools:context=".MainActivity">

    <EditText
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:hint="Username"
            android:inputType="textEmailAddress"
            android:id="@+id/usernameEditText"/>

    <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:hint="Password"
            android:inputType="textPassword"
            android:id="@+id/passwordEditText"/>

</LinearLayout>

如果希望诸如标签之类的内容始终存在,也可以使用material文本字段,https://material.io/design/components/text-fields.html

代码语言:javascript
复制
<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <EditText
        android:id="@+id/usernameEditText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textEmailAddress"
        android:hint="Username"/>

</android.support.design.widget.TextInputLayout>
票数 1
EN

Stack Overflow用户

发布于 2018-06-19 12:56:16

如果您可以使用ConstraintLayout来减少layout hierarchy,这是最佳实践。否则,您可以使用嵌套LinearLayout

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

https://stackoverflow.com/questions/50919273

复制
相关文章

相似问题

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