Java 如何在线性布局中垂直组合两个编辑文本
这是我的目标: 我有一个Java 如何在线性布局中垂直组合两个编辑文本,java,android,android-layout,android-edittext,android-linearlayout,Java,Android,Android Layout,Android Edittext,Android Linearlayout,这是我的目标: 我有一个线性布局,其中所有东西都是居中的既有垂直的也有水平的 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"
线性布局
,其中所有东西都是居中的
既有垂直的
也有水平的
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/top_edittext_form_bg"
android:hint="Email or Username"
android:layout_gravity="center_horizontal"
android:layout_margin="5pt"/>
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bottom_edittext_form_bg"
android:inputType="textPassword"
android:hint="Password"
android:layout_gravity="center_horizontal"
android:layout_margin="5pt" />
...
...
我一直在胡闹,试图去掉版面空白
,但这会影响所有元素(甚至是这两个元素下面的元素)
我有没有办法简单地将这两个编辑文本
组合在一起,而不影响我的线性布局
?试试这个:
...
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/top_edittext_form_bg"
android:hint="Email or Username"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5pt"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt"
/>
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bottom_edittext_form_bg"
android:inputType="textPassword"
android:hint="Password"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5pt"
android:layout_marginLeft="5pt"
android:layout_marginRight="5pt"
/>
...
。。。
...
告诉我它是否有效。:) 如果您想在下面使用其他组件,您可能需要一个嵌套的
LinearLayout
,它只包含有问题的toEditText
s。