I have a ScrollView
inside which is an EditText
which is set to scroll vertically. But it does not scrolls. Instead the whole layout scrolls, Whenever i try to scroll the EditText
.
Below is the code -
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="39dp"
android:text="Title"
android:textColor="#3bb9ff"
android:textSize="15sp" />
<EditText
android:id="@+id/Text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Title"
android:singleLine="true" >
<requestFocus />
</EditText>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Content"
android:layout_marginTop="50dp"
android:textColor="#3bb9ff"
android:textSize="15sp"
/>
<EditText
android:id="@+id/newTodoText"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:minLines="2"
android:maxLines="7"
android:hint="Write something"
android:scrollbars = "vertical" >
</EditText>
<Button
android:id="@+id/Add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Add" />
</LinearLayout>
</ScrollView>
The EditText with id "newTodoText" is in question here.
You have to just replace your
<ScrollView ></ScrollView>
with this Custom ScrollView like<com.example.VerticalScrollview > </com.example.VerticalScrollview >
you should use NestedScrollView class. This class support child scrolling inside parent scrolling. This class can be a child or a parent.
Use this Code Its Working
in Xml
in Pragraming
This will make your entire layout scrollable.
For setting your edittext scrollable add
android:scrollbars="vertical"
to your edittextIn your code its already written
Remove the from code.It will work fine
ScrollView
as your parent most layout. That's reason your whole layout gets scrolled.android:scrollbars = "vertical"
which means if the EditText grows a vertical srollBar will appear. You will get the scrollbar and scrolling effect only if edittext has data high enough..Hope this helps...