我有一个带有一些元素的垂直线性布局,但在一个位置我想要 1 行中有 2 个 EditText。我在其中使用了水平线性布局,但 Android Studio 说这对性能非常不利。
有没有办法在没有嵌套布局的情况下做到这一点?(XML 或以编程方式)
XML:
<?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="fill_parent"
android:layout_height="fill_parent"
android:background="@color/cyan_50"
android:orientation="vertical"
tools:context="com.secutschett.RegisterActivity"
android:weightSum="100">
<android.support.design.widget.AppBarLayout
android:layout_width="fill_parent"
android:layout_height="?attr/actionBarSize"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/cyan_700"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/app_name"
app:titleTextColor="@color/cyan_50" />
</android.support.design.widget.AppBarLayout>
<TextView
android:id="@+id/step1TextView"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="10"
android:text="@string/step1TextViewText"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />
<TextView
android:id="@+id/placeholder1"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="10" />
<EditText
android:id="@+id/step1UsernameEditText"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="10"
android:hint="@string/step1UsernameEditTextHint"
android:inputType="text"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textColorHint="@color/blue_grey_400" />
<EditText
android:id="@+id/step1NicknameEditText"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="10"
android:hint="@string/step1NicknameEditTextHint"
android:inputType="text"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textColorHint="@color/blue_grey_400" />
<TextView
android:id="@+id/placeholder2"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="10" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="10"
android:orientation="horizontal">
<EditText
android:id="@+id/step1PasswordEditText"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="50"
android:hint="@string/step1PasswordEditTextHint"
android:inputType="text|textPassword"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textColorHint="@color/blue_grey_400" />
<EditText
android:id="@+id/step1RepeatPasswordEditText"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="50"
android:hint="@string/step1RepeatPasswordEditTextHint"
android:inputType="text|textPassword"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textColorHint="@color/blue_grey_400" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="10"
android:orientation="horizontal">
<EditText
android:id="@+id/step1EmailAddressEditText"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="50"
android:hint="@string/step1EmailAddressEditTextHint"
android:inputType="text|textEmailAddress"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textColorHint="@color/blue_grey_400" />
<EditText
android:id="@+id/step1RepeatEmailAddressEditText"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="50"
android:hint="@string/step1RepeatEmailAddressEditTextHint"
android:inputType="text|textEmailAddress"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.AppCompat"
android:textColorHint="@color/blue_grey_400" />
</LinearLayout>
<TextView
android:id="@+id/placeholder3"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="10" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="10"
android:orientation="horizontal">
<Button
android:id="@+id/step1RegisterButton"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="30"
android:text="@string/registerButtonName" />
<TextView
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="10" />
<CheckBox
android:id="@+id/step1AgreeCheckBox"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="10" />
<TextView
android:id="@+id/step1PoliciesTextView"
android:layout_width="0dip"
android:layout_height="fill_parent"
android:layout_weight="50"
android:maxLines="10"
android:text="@string/step1PoliciesTextViewText"
android:textColorLink="@color/blue_500" />
</LinearLayout>
<com.roide.progressdotslib.ProgressDotWidget
android:id="@+id/progress_dots1"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="10"
android:background="@color/cyan_600"
android:padding="@dimen/standard_margins" />
</LinearLayout>