简体   繁体   中英

Start from the top of the layout / activity

I'm working on android app, and I have the screen where the user can register and put the information about himself. it's a long screen where the user needs to scroll down to complete it. When I'm testing it with the emulator, the courser always goes to the last EditText box which is android:id="@+id/tbJoinBio .

I want the courser to start from the top box android:id="@+id/tbJoinUsername

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@color/light_green" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_weight="0.29" >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="950dp" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="303dp"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginTop="25dp"
                    android:text="@string/join_welcome" />

                <TextView
                    android:id="@+id/lblLoginUsername"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/textView1"
                    android:layout_below="@+id/textView1"
                    android:layout_marginTop="18dp"
                    android:text="@string/login_label_username"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <EditText
                    android:id="@+id/tbJoinUsername"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/lblLoginUsername"
                    android:layout_below="@+id/lblLoginUsername"
                    android:ems="10"
                    android:text="user"
                    android:inputType="text" />

                <TextView
                    android:id="@+id/lblLoginPassword"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/tbJoinUsername"
                    android:layout_below="@+id/tbJoinUsername"
                    android:layout_marginTop="10dp"
                    android:text="@string/login_label_password"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <EditText
                    android:id="@+id/tbJoinPassword"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/lblLoginPassword"
                    android:layout_below="@+id/lblLoginPassword"
                    android:text="password"
                    android:ems="10"
                    android:inputType="textPassword" />

                <TextView
                    android:id="@+id/TextView01"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/tbJoinPassword"
                    android:layout_marginTop="16dp"
                    android:text="@string/join_password_confirm"
                    android:textAppearance="?android:attr/textAppearanceMedium" />


                <EditText
                    android:id="@+id/tbJoinPassword2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/TextView01"
                    android:ems="10"
                    android:inputType="textPassword"
                    android:text="password" />

                <TextView
                    android:id="@+id/TextView02"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/tbJoinPassword2"
                    android:layout_marginTop="18dp"
                    android:text="@string/join_email"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <EditText
                    android:id="@+id/tbJoinEmail"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/TextView02"
                    android:ems="10"
                    android:text="user@user.com"
                    android:inputType="text" />

                <Button
                    android:id="@+id/btnRegister"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:text="@string/join_button_register" />

                <TextView
                    android:id="@+id/lblFirstName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/tbJoinEmail"
                    android:layout_marginTop="14dp"
                    android:text="First Name"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <EditText
                    android:id="@+id/tbJoinFirstName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/lblFirstName"
                    android:ems="10"
                    android:text="User"
                    android:inputType="text" >

                    <requestFocus />
                </EditText>

                <TextView
                    android:id="@+id/lblMiddleName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignTop="@+id/lblFirstName"
                    android:layout_marginLeft="150dp"
                    android:layout_toRightOf="@+id/lblFirstName"
                    android:text="MI"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <EditText
                    android:id="@+id/tbJoinMiddleName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="M"
                    android:layout_alignLeft="@+id/lblMiddleName"
                    android:gravity="center"
                    android:layout_below="@+id/lblMiddleName"
                    android:ems="2"
                    android:inputType="text" >

                    <requestFocus />
                </EditText>                

                <TextView
                    android:id="@+id/lblLastName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/tbJoinFirstName"
                    android:layout_marginTop="14dp"
                    android:text="Last Name"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <EditText
                    android:id="@+id/tbJoinLastName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Name"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/lblLastName"
                    android:ems="10"
                    android:inputType="text" >

                    <requestFocus />
                </EditText>

                <TextView
                    android:id="@+id/lbldob"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/tbJoinLastName"
                    android:layout_marginTop="14dp"
                    android:text="DOB (MMDDYYYY)"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <EditText
                    android:id="@+id/tbJoindob"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="10221955"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/lbldob"
                    android:ems="10"
                    android:inputType="text" >

                    <requestFocus />

                </EditText>      

                <TextView
                    android:id="@+id/lblStreetAddr"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/tbJoindob"
                    android:layout_marginTop="14dp"
                    android:text="Street Address"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <EditText
                    android:id="@+id/tbJoinStreetAddr"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="United States"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/lblStreetAddr"
                    android:ems="10"
                    android:inputType="text" >

                    <requestFocus />
                </EditText> 

                <TextView
                    android:id="@+id/lblPhoneNum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/tbJoinStreetAddr"
                    android:layout_marginTop="14dp"
                    android:text="Phone Number"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <EditText
                    android:id="@+id/tbJoinPhoneNum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="2155555555"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/lblPhoneNum"
                    android:ems="10"
                    android:inputType="text" >

                    <requestFocus />

                </EditText>      


                <TextView
                    android:id="@+id/lblBio"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/tbJoinPhoneNum"
                    android:layout_marginTop="14dp"
                    android:text="About you"
                    android:textAppearance="?android:attr/textAppearanceMedium" />

                <EditText
                    android:id="@+id/tbJoinBio"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="I'm awesome"
                    android:layout_alignParentLeft="true"
                    android:layout_below="@+id/lblBio"
                    android:ems="10"
                    android:inputType="text" >

                    <requestFocus />

                </EditText>                
            </RelativeLayout>

        </LinearLayout>
    </ScrollView>



</LinearLayout>

Thanks

删除标签

<requestFocus />

<requestFocus/>标记移至android:id="@+id/tbJoinUsername元素。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM