Reputation:
I want edittext which will have 3 lines and if the edittext content exceeds 3 lines limit then vertical scrollbar should be visible to user.
Upvotes: 14
Views: 23132
Reputation: 822
I think this question is more about adding Multiline editText inside scrollview.
Inside scrollview, If your EditText has more text you wont be able to scroll inside, rather whole page will scroll.
You can achieve this with help of TouchListener.
edtDescription = (EditText)findViewById(R.id.edt_description);
edtDescription.setVerticalScrollBarEnabled(true);
edtDescription.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
edtDescription.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET);
edtDescription.setMovementMethod(ScrollingMovementMethod.getInstance());
edtDescription.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
view.getParent().requestDisallowInterceptTouchEvent(true);
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0)
{
view.getParent().requestDisallowInterceptTouchEvent(false);
}
return false;
}
});
Upvotes: 4
Reputation: 224
may work 100%
<EditText
android:inputType="textMultiLine"
android:lines="int number" <!-- Total Lines prior display -->
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollbars="vertical"/>
Upvotes: 20
Reputation: 41
if textview lines exceeds two line scrollview will scroll
if (mTvContacts.getLayout().getLineCount() >= 2) {
if (scrollContactsHeight == 0)
scrollContactsHeight = scrollContacts.getHeight();
scrollContacts.getLayoutParams().height = scrollContactsHeight * 2;
} else {
if (scrollContactsHeight == 0)
scrollContacts.getLayoutParams().height = scrollContacts.getHeight();
else
scrollContacts.getLayoutParams().height = scrollContacts.getHeight() / 2;
}
<ScrollView
android:id="@+id/scrollContacts"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_toRightOf="@+id/tvTo"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/imgAddContacts">
<TextView
android:id="@+id/tvContacts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="wfd"
android:textColor="#000" />
</ScrollView>
Upvotes: 0
Reputation: 9700
Apply this code snippets...you will get your requirement right. And one thing to note, you have to give hard coded Height of ScrollView...I give here as 70dip.
<ScrollView
android:layout_width="fill_parent"
android:layout_height="70dip" >
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="false" />
</ScrollView>
Upvotes: 0
Reputation: 1814
Use inputType="textMultiLine"
and set android:lines="3"
like:
<EditText
android:inputType="textMultiLine"
android:lines="3" <!-- Total Lines prior display -->
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollbars="vertical"
/>
Upvotes: 12
Reputation: 606
In you edit Text just add
android:inputType="textMultiLine"
android:maxLines="3">
Upvotes: 3
Reputation: 4255
Have tried with ? :
<EditText
android:id="@+id/edt_note"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:maxLines="3"
>
Upvotes: 0