Reputation: 11
I have a HorizontalscrollView
inside a horizontal LinearLayout
and for some reason I can only scroll vertically. Somewhere I read that the it needs to be within a horizontal LinearLayout
but it still didn't fix the problem. Help appreciated a lot. Thanks..
Here's the code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#deefed"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Textview"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:digits="0123456789."
android:ems="10"
android:hint="edittext"
android:inputType="number|numberDecimal"
android:maxLines="1" />
</HorizontalScrollView>
<Spinner
android:layout_width="match_parent"
android:layout_height="match_parent">
</Spinner>
</LinearLayout>
Upvotes: 0
Views: 44
Reputation: 1267
It's your EditText
that scrolls vertically, not the HorizontalScrollView
.
If you want that the text goes only horizontally change it this way:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:digits="0123456789."
android:ems="10"
android:hint="edittext"
android:inputType="number|numberDecimal"
android:scrollHorizontally="true"
android:singleLine="true"
android:maxLines="1" />
By adding
android:scrollHorizontally="true"
android:singleLine="true"
It will stay in single row and it will scroll horizontally.
Upvotes: 1
Reputation: 184
If I get it correct, you want to scroll your text in EditText horizontally. I think you do not need a horizontal scroll view for that and the problem could be solved by just using android:singleLine="true" in EditText.
android:maxLines is so confusing, because it does something very different. It only sets the vertical view bound of EditText to show as many lines at a time as it's value, like android:maxLines = "5" would show 5 lines at a time in the EditText view.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#deefed"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Textview"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:digits="0123456789."
android:ems="10"
android:hint="edittext"
android:inputType="number|numberDecimal"
android:singleLine="true" />
<Spinner
android:layout_width="match_parent"
android:layout_height="match_parent">
</Spinner>
</LinearLayout>
</LinearLayout>
Upvotes: 0