我只是在佈局中有一個表單。我只是想顯示左上角的部分(即當表單被點擊時,表單的起始字段。我使用請求焦點。但它不工作。當我打開窗體的窗體的中間部分進入視圖,只有在滾動到頂部我可以得到第一個字段。我可以如何解決這個問題,以便我可以在窗體打開時進入窗體的起始部分。這是我的。窗體佈局請求重點無法正常工作
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context="com.example.user.educationhunt.UniversityRegistration">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:paddingBottom="22dp"
android:paddingLeft="22dp"
android:paddingRight="22dp"
android:paddingTop="22dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_marginBottom="4dp"
android:text="Name:">
</TextView>
<EditText
android:id="@+id/register_school_name"
android:layout_width="match_parent"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:textSize="12dp"
android:hint="School Name*"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content">
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_marginBottom="4dp"
android:text="Address:"/>
<EditText
android:id="@+id/register_school_address"
android:layout_width="match_parent"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:textSize="12dp"
android:hint="School Address*"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<Spinner
android:id="@+id/register_school_district"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:layout_height="wrap_content" />
<Spinner
android:id="@+id/register_school_country"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_marginBottom="4dp"
android:text="Phone:"/>
<EditText
android:id="@+id/register_school_phone"
android:layout_width="match_parent"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:textSize="12dp"
android:inputType="numberDecimal"
android:hint="School Phone no*"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_marginBottom="4dp"
android:text="Email:"/>
<EditText
android:id="@+id/register_school_email"
android:layout_width="match_parent"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:textSize="12dp"
android:inputType="textEmailAddress"
android:hint="Valid email address*"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_marginBottom="4dp"
android:text="Website:"/>
<EditText
android:id="@+id/register_school_website"
android:layout_width="match_parent"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:textSize="12dp"
android:hint="School Website*"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18dp"
android:layout_marginBottom="4dp"
android:text="Institution Type:"/>
<Spinner
android:id="@+id/register_school_institution"
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:textSize="18dp"
android:text="Establishment Date:"/>
<EditText
android:id="@+id/register_school_estdate"
android:layout_width="match_parent"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:textSize="12dp"
android:hint="School establishment date*"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:textSize="18dp"
android:text="Fee Structure:"/>
<LinearLayout
android:id="@+id/addSchoolProgram"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<Spinner
android:id="@+id/register_school_level"
android:layout_width="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<EditText
android:id="@+id/register_school_annualFee"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:inputType="numberDecimal"
android:textSize="12dp"
android:hint="Total Annual fee(NRs)*"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/addSchoolProgram1"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<Spinner
android:id="@+id/register_school_level1"
android:layout_width="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<EditText
android:id="@+id/register_school_annualFee1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:inputType="numberDecimal"
android:textSize="12dp"
android:hint="1Total Annual fee(NRs)*"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:visibility="gone"
android:id="@+id/addSchoolProgram2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<Spinner
android:id="@+id/register_school_level2"
android:layout_width="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<EditText
android:id="@+id/register_school_annualFee2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:inputType="numberDecimal"
android:textSize="12dp"
android:hint="2Total Annual fee(NRs)*"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:visibility="gone"
android:id="@+id/addSchoolProgram3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<Spinner
android:id="@+id/register_school_level3"
android:layout_width="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<EditText
android:id="@+id/register_school_annualFee3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:textSize="12dp"
android:inputType="numberDecimal"
android:hint="3Total Annual fee(NRs)*"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:visibility="gone"
android:id="@+id/addSchoolProgram4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<Spinner
android:id="@+id/register_school_level4"
android:layout_width="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<EditText
android:id="@+id/register_school_annualFee4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:inputType="numberDecimal"
android:textSize="12dp"
android:hint="4Total Annual fee(NRs)*"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:visibility="gone"
android:id="@+id/addSchoolProgram5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<Spinner
android:id="@+id/register_school_level5"
android:layout_width="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<EditText
android:id="@+id/register_school_annualFee5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:inputType="numberDecimal"
android:textSize="12dp"
android:hint="5Total Annual fee(NRs)*"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:visibility="gone"
android:id="@+id/addSchoolProgram6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<Spinner
android:id="@+id/register_school_level6"
android:layout_width="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<EditText
android:id="@+id/register_school_annualFee6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rounded_edittext"
android:padding="11dp"
android:inputType="numberDecimal"
android:textSize="12dp"
android:hint="6Total Annual fee(NRs)*"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:visibility="gone"
android:id="@+id/addSchoolProgram7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="7dp"
android:background="#6c8487"/>
<Spinner
android:id="@+id/register_school_level7"
android:layout_width="match_parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
嘗試請求注重形式的第一EditText上那是一個與id register_school_name。 –
兄我已經嘗試過了。它不起作用 – therameshbista
如果你在activity的setContentView()中使用這個佈局,那麼第一個EditText應該會自動獲得焦點。不過要確保設置ScrollView android:focusable =「true」和android:focusableInTouchMode =「true」並嘗試請求第一個editText的焦點。 –