Reputation: 675
I placed an edit text within a scroll view with height = match_parent
and expected its height to be equal to the scroll view but it's not. Its height behaves like wrap_content
which means if there are no text in the EditText, I will have to point the cursor at the first "line" for the soft keyboard to popup, what I want is I can touch anywhere in the screen (the scroll view) and the soft keyboard pops up.
Below is the layout, thanks for your helps.
<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"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:gravity="top"
android:padding="10dp"
android:textSize="16sp"
android:textColor="@android:color/black">
</EditText>
</ScrollView>
<Button
android:id="@+id/btnPaste"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/paste"
android:gravity="center"
android:onClick="pasteData"
android:layout_marginLeft="5dp"
android:layout_marginRight="6dp"
android:layout_marginBottom="5dp"
android:background="@drawable/rounded_corner_button"
android:textColor="@android:color/white"/>
</LinearLayout>
Layout capture :
Upvotes: 3
Views: 1105
Reputation: 31
Implement this to your EditText in xml file:
android:scrollbars="vertical"
Implement this in onCreate():
editText.setMovementMethod(new ScrollingMovementMethod());
Then, you won't need scrollview if you only use it for textview, it simply makes scrollable only your textview.
Upvotes: 0
Reputation: 2594
You can control the edit text by changing minLines
attribute
for example :
<EditText
android:id="@+id/ed_comment"
style="@style/EditText.NoBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:hint="@string/write_comment_hint"
android:minLines="40"
android:textSize="16sp"/>
and instead of wrapping the EditText by scrollView add this attribute to editText
android:scrollbars="vertical"
result:
Upvotes: 3