UPDATE
我想尽可能使用XML实现这个目标,因为我有太多2个列圆柱布局。我不知道问题是使用LinearLayout(只是猜测)还是别的。我按顺序绘制它们(从街道 - > Brgy - > City - > ZipCode等)这就是为什么我很困惑为什么它不按照我创建它们的顺序朝着正确的方向前进
只需要我的XML / UI帮助。我有一个EditTexts的2列设计,我的目标是当我从左侧元素的键盘旁边按下时,它将转到右侧元素然后在左下角旁边,依此类推(根据照片附件底部:从街道 - > Brgy - > City - > ZipCode等)。
但是当我按下它时,我遇到了问题,它一直在下降。当我在左侧元素时,它在左下侧并且在右侧元素上相同,它向右下方。如何根据我的目标制作模式?尝试了这些,但仍然出现问题。
android:nexFocusRight="@+id/.."
和
android:nextFocusForward="@+id/.."
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/TitleLayout1"
android:layout_marginLeft="@dimen/marginSide1"
android:layout_marginRight="@dimen/marginSide1"
android:minHeight="25px"
android:layout_marginTop="@dimen/marginTop2"
android:background="@color/white">
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="20px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/TitleBackround1"
android:background="@color/bluegreendark"
android:layout_gravity="center" />
<TextView
android:text="Personal Data"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/PDRN_Title1"
android:background="@color/white"
android:textColor="@color/darkgray"
android:paddingLeft="@dimen/paddingSide1"
android:paddingRight="@dimen/paddingSide1"
android:layout_gravity="center"
android:fontFamily="@string/fontFamily"
android:textSize="@dimen/textSizeHeader" />
</FrameLayout>
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutApplicant">
<TextView
android:text="Applicant"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/lightgray"
android:layout_marginLeft="@dimen/marginSide1"
android:layout_marginTop="@dimen/marginSide1"
android:fontFamily="@string/fontFamily"
android:textStyle="bold" />
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutStreet"
android:layout_marginLeft="@dimen/marginSide2"
android:layout_marginRight="@dimen/marginSide2"
android:weightSum="100"
android:layout_width="match_parent">
<EditText
android:inputType="textPostalAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/PD_Street"
android:hint="Street"
android:layout_weight="50"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:singleLine="true"
android:nextFocusForward="@+id/PD_Baranggay" <!--Just tried it here-->
android:nextFocusRight="@+id/PD_Baranggay" <!--Just tried it here-->
android:maxLength="@string/genericLongLength" />
<EditText
android:inputType="textPostalAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/PD_Baranggay"
android:hint="Brgy"
android:layout_weight="50"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:singleLine="true"
android:maxLength="@string/genericLongLength" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutZipCode"
android:layout_marginLeft="@dimen/marginSide2"
android:layout_marginRight="@dimen/marginSide2"
android:weightSum="100">
<EditText
android:inputType="textPostalAddress"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/PD_City"
android:layout_weight="50"
android:hint="City"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:singleLine="true"
android:maxLength="@string/genericLength" />
<EditText
android:inputType="number"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="@+id/PD_ZipCode"
android:layout_weight="50"
android:hint="Zip Code"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:singleLine="true"
android:maxLength="@string/yearLength" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutMobile"
android:layout_marginLeft="@dimen/marginSide1"
android:layout_marginRight="@dimen/marginSide1"
android:weightSum="100"
android:layout_width="match_parent">
<EditText
android:inputType="phone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/PD_Telephone"
android:hint="Telephone"
android:layout_weight="50"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:singleLine="true"
android:maxLength="@string/contactLength" />
<EditText
android:inputType="phone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/PD_MobileNumber"
android:hint="Mobile"
android:layout_weight="50"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:singleLine="true"
android:maxLength="@string/contactLength" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutOccularInspected"
android:layout_marginLeft="@dimen/marginSide1"
android:layout_marginRight="@dimen/marginSide1"
android:weightSum="100"
android:layout_width="match_parent">
<EditText
android:inputType="numberDecimal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/PD_LengthOfStay"
android:hint="Yrs of Stay"
android:layout_weight="50"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:singleLine="true"
android:maxLength="@string/numberDecimalLength" />
<CheckBox
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/PD_OccularInspected"
android:text="Occular Inspected"
android:layout_weight="50"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily" />
</LinearLayout>
<EditText
android:inputType="textPostalAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/PD_ProvincialAddress"
android:hint="Provincial Address"
android:layout_marginLeft="@dimen/marginSide1"
android:layout_marginRight="@dimen/marginSide1"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:singleLine="true"
android:maxLength="@string/addressLength" />
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutCivilStatus"
android:layout_marginLeft="@dimen/marginSide1"
android:layout_marginRight="@dimen/marginSide1"
android:weightSum="100"
android:layout_width="match_parent">
<Spinner
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/PD_CivilStatus"
android:layout_weight="50"
android:spinnerMode="dialog"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:layout_marginTop="@dimen/marginNegativeTop2" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/PDRN_EditTextCivilStatusOthers"
android:layout_weight="50"
android:hint="Pls specify"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:visibility="gone"
android:singleLine="true"
android:maxLength="@string/otherLength" />
</LinearLayout>
<EditText
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/marginSide1"
android:layout_marginRight="@dimen/marginSide1"
android:id="@+id/PD_NumberOfDependents"
android:hint="No. of Dependents"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:singleLine="true"
android:maxLength="@string/numberLength" />
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutSubjectNationality"
android:layout_marginLeft="@dimen/marginSide1"
android:layout_marginRight="@dimen/marginSide1"
android:weightSum="100"
android:layout_width="match_parent">
<Spinner
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="50"
android:id="@+id/PD_SpinnerSubjectNationality"
android:spinnerMode="dialog"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:layout_marginTop="@dimen/marginNegativeTop2" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/PD_EditTextSubjectNationalityACR"
android:hint="ACR No."
android:layout_weight="50"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:visibility="gone"
android:singleLine="true"
android:maxLength="@string/genericLength" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:id="@+id/linearLayoutSpouseNationality"
android:layout_marginLeft="@dimen/marginSide1"
android:layout_marginRight="@dimen/marginSide1"
android:weightSum="100"
android:layout_width="match_parent">
<Spinner
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="50"
android:id="@+id/PD_SpinnerSpouseNationality"
android:spinnerMode="dialog"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:layout_marginTop="@dimen/marginNegativeTop2" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/PD_EditTextSpouseNationalityACR"
android:hint="ACR No."
android:layout_weight="50"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:visibility="gone"
android:singleLine="true"
android:maxLength="@string/genericLength" />
</LinearLayout>
</LinearLayout>
见附图
只需将此添加到您的EditText
android:imeOptions="actionNext"
android:nextFocusDown="@+id/yourNextEditText"
像这个。
<EditText
android:inputType="textPostalAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/PD_Street"
android:hint="Street"
android:layout_weight="50"
android:textColor="@color/darkgray"
android:textSize="@dimen/textSizeCommon"
android:fontFamily="@string/fontFamily"
android:singleLine="true"
android:imeOptions="actionNext" <!--ADD THIS LINE -->
android:nextFocusDown="@+id/PD_Barangay" <!--ADD THIS LINE -->
android:nextFocusForward="@+id/PD_Baranggay" <!--REMOVE THIS LINE-->
android:nextFocusRight="@+id/PD_Baranggay" <!--REMOVE THIS LINE-->
android:maxLength="@string/genericLongLength" />
并在其他EditText
组件中执行此操作,您需要专注于按Next
按钮。