Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why my scrollHorizontally doesn't work?

Tags:

android

scroll

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
tools:context=".MainActivity" >

<TextView
    android:id="@+id/instruction_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollHorizontally="true"
    android:text="@string/Texto_de_abertura"
    android:textColor="#00FF00" />

<TableRow>code<TableRow>
</TableLayout>

This is the code I'm using. The string Texto_de_abertura is really big, and it keeps using a lot of lines to put the entire string on the screen, not only one with scroll horizontally on as I wanted.

like image 255
rado Avatar asked Dec 01 '13 01:12

rado


1 Answers

To scroll horizontally you can place the TextView inside a HorizontalScrollView:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
tools:context=".MainActivity" >

    <HorizontalScrollView 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

        <TextView
        android:id="@+id/instruction_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollHorizontally="true"
        android:text="@string/Texto_de_abertura"
        android:textColor="#00FF00" />

   </HorizontalScrollView>

<TableRow></TableRow>
</TableLayout>

The Android documentation describes scrollHorizontally as "Whether the text is allowed to be wider than the view (and therefore can be scrolled horizontally)" meaning a HorizontalScrollView is required to make the view scroll alongside setting the property to allow it to scroll. https://developer.android.com/reference/android/widget/TextView.html#attr_android:scrollHorizontally

like image 192
Hugh McGrade Avatar answered Oct 17 '22 14:10

Hugh McGrade