I have a simple layout with nested elements in its xml inside ScrollView, its basically a form to get user input with several objects EditTextand others. One of mine EditTexthas an attribute
android:lines="2"
for the field the user’s address, and it should contain 2 lines. Therefore, when the user enters input in EditText, the Enter key is displayed on the soft keyboard and when you press this key again, it ScrollViewautomatically scrolls down each time you press Enter and EditText loses focus and the layout automatically scrolls down to it. How to stop it.
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/rel_main_footer"
android:layout_below="@+id/enquiry_header" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tv_wit_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/wit_head"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#7f0100" />
<LinearLayout
android:id="@+id/li1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_wit_header"
android:orientation="horizontal"
android:padding="8dp" >
<TextView
android:id="@+id/tv_wit_owner"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="@string/wit_name"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/et_wit_owner"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="#00000000"
android:hint="@string/hint_set_owner"
android:inputType="text"
android:singleLine="true"
android:textColor="#7f0000"
android:textColorHint="#a65b5a" />
</LinearLayout>
<View
android:id="@+id/v1"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_below="@+id/li1"
android:background="#A4A4A4" />
<LinearLayout
android:id="@+id/li2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/v1"
android:orientation="horizontal"
android:padding="8dp" >
<TextView
android:id="@+id/tv_wit_address"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="@string/ud_address"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/et_wit_address"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="#00000000"
android:gravity="top|left"
android:hint="@string/hint_set_address"
android:lines="2"
android:singleLine="true"
android:scrollbars="vertical"
android:textColor="#7f0000"
android:textColorHint="#a65b5a" />
</LinearLayout>
<View
android:id="@+id/v2"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_below="@+id/li2"
android:background="#A4A4A4" />
<LinearLayout
android:id="@+id/li3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/v2"
android:orientation="horizontal"
android:padding="8dp" >
<TextView
android:id="@+id/tv_wit_number"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:text="@string/wit_number"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/et_wit_number"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1.0"
android:background="#00000000"
android:hint="@string/hint_wit_number"
android:inputType="phone"
android:singleLine="true"
android:textColor="#7f0000"
android:textColorHint="#a65b5a" />
</LinearLayout>
<View
android:id="@+id/v3"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_below="@+id/li3"
android:background="#A4A4A4" />
<LinearLayout
android:id="@+id/li4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/v3"
android:orientation="vertical"
android:padding="8dp" >
<TextView
android:id="@+id/tv_wit_notes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wit_notes"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/et_wit_notes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:gravity="top|left"
android:hint="@string/hint_wit_notes"
android:inputType="textMultiLine"
android:lines="5"
android:maxLines="5"
android:textColor="#7f0000"
android:textColorHint="#a65b5a" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
source
share