为什么我的scrollHorizo​​ntally不起作用?

时间:2013-12-01 01:08:44

标签: 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>

这是我正在使用的代码。字符串Texto_de_abertura真的很大,并且它一直使用很多行来将整个字符串放在屏幕上,而不仅仅是一个水平滚动的字符串。

1 个答案:

答案 0 :(得分:6)

要水平滚动,可以将TextView放在Horizo​​ntalScrollView:

<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>

Android文档将scrollHorizo​​ntally描述为“文本是否允许宽于视图(因此可以水平滚动)”意味着需要使用Horizo​​ntalScrollView使视图滚动并设置属性以允许滚动。 https://developer.android.com/reference/android/widget/TextView.html#attr_android:scrollHorizontally