我是android的新手,定位元素与web的定位元素有很大不同。
所以我想做的是:
Login: ______
Password: _____
通过将linearLayout设置为垂直方向,我可以得到以下结果:
Login:
__
Password:
__
或者这样,水平方向:
Login:_____Password:_____
我如何将其混合在一起并实现我所需要的?
当前代码:
<?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>
发布于 2018-06-19 09:01:51
嵌套您的线性布局。有一个垂直的顶层线性布局,里面有两个水平的线性布局,每一个都做你输出的一行。
发布于 2018-06-19 09:24:34
通常在移动设备上,你不需要像在web上那样使用标签。EditText
上的setHint
应该足以让用户清楚地了解字段的用途。
<?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
<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>
发布于 2018-06-19 12:56:16
如果您可以使用ConstraintLayout来减少layout hierarchy
,这是最佳实践。否则,您可以使用嵌套LinearLayout
。
https://stackoverflow.com/questions/50919273
复制相似问题