I'm working on a calculator. I noticed that in the default android calc you can scroll the textview horizontally. I looked up the documentation and found out about the attribute android:scrollHorizontally
but after adding it to the textview I still cannot do horizontal scroll, there is no further info about it on the documentation leading me to think that only adding the attr should suffice. This is the calculator's textview:
<TextView android:id="@+id/edit_text"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".8"
android:singleLine="true"
android:scrollHorizontally="true"
android:gravity="center|right"
android:text="0" />
When characters exceed the textview width the string is trimmed and ... appear at it's end. What am I doing wrong?
<HorizontalScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_width="40dp"
android:layout_height="wrap_content"
android:scrollHorizontally="true"
android:text="Horizontal scroll view will work now"/>
</HorizontalScrollView>
This is how you can make textview scroll horizontally.
I'm a bit late but I managed to achieve same result without adding the HorizontalScrollView
EditText
extends TextView
to support scrolling and selection. So, you can use the EditText
as a TextView
(touch, focus and cursor are disabled).
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent" --> This remove that line at the bottom
android:clickable="false" --> It can be true if you need to handle click events
android:cursorVisible="false" --> Hide the cursor
android:focusable="false" --> Disable focus
android:singleLine="true"
android:text="This is a very long text that won't be possible to display in a single line"/>
I'm just not able to test in a wide range of devices... I'm just sharing because it may be useful to someone else.
Just use this
textview.setMovementMethod(new ScrollingMovementMethod());
textview.setHorizontallyScrolling(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With