0

这是我的 Android 应用程序的 XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="5"
    android:background="@drawable/gradient"
    android:gravity="fill_horizontal"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".PNRActivity" >

    <EditText
        android:id="@+id/pnr_num"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:gravity="top|center"
        android:hint="@string/pnr_number"
        android:inputType="number"
        android:maxLength="10" >

        <requestFocus />
    </EditText>

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingTop="45dip" >

        <Button
            android:id="@+id/btnStatus"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/btn_pnr"
            android:text="@string/btnGetStatus" />

        <TextView
            android:id="@+id/centerPoint"
            android:layout_width="5dip"
            android:layout_height="wrap_content"
            android:paddingTop="15dip"
            android:text="" />

        <Button
            android:id="@+id/btnClear"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/btn_pnr"
            android:text="@string/btnClear" />
    </LinearLayout>

    <TextView
        android:id="@+id/txtOutput"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/linearLayout1"
        android:layout_alignRight="@+id/linearLayout1"
        android:layout_below="@+id/linearLayout1"
        android:layout_marginTop="20dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:maxLines = "10"
        android:text="@string/txtOut"
        android:scrollbars = "vertical"
        android:freezesText="true"
        android:background="@drawable/border"
        android:padding="10dip" />

</RelativeLayout>

我想让 ID 为 txtOutput 的 TextView 可滚动。我通过以下方式实现了这一目标:

textView.setMovementMethod(new ScrollingMovementMethod());

但是在水平方向滚动不起作用!我还使用 freezesText 使文本以水平布局显示。但是水平滚动在水平视图中仍然不起作用。我怎样才能让它工作?

4

1 回答 1

0

将您的布​​局从相对布局更改为水平滚动视图到您的布局,如下所示...

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="5"
    android:background="@drawable/gradient"
    android:gravity="fill_horizontal"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".PNRActivity" >

    <RelativeLayout androidid:"@+id:RelLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="5"
        android:background="@drawable/gradient"
        android:gravity="fill_horizontal"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin" >

        <EditText
            android:id="@+id/pnr_num"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:gravity="top|center"
            android:hint="@string/pnr_number"
            android:inputType="number"
            android:maxLength="10" >

            <requestFocus />
        </EditText>

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:paddingTop="45dip" >

            <Button    
                android:id="@+id/btnStatus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/btn_pnr"
                android:text="@string/btnGetStatus" />

            <TextView
                android:id="@+id/centerPoint"
                android:layout_width="5dip"
                android:layout_height="wrap_content"
                android:paddingTop="15dip"
                android:text="" />

            <Button
                android:id="@+id/btnClear"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/btn_pnr"
                android:text="@string/btnClear" />
        </LinearLayout>

        <TextView
            android:id="@+id/txtOutput"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/linearLayout1"
            android:layout_alignRight="@+id/linearLayout1"
            android:layout_below="@+id/linearLayout1"
            android:layout_marginTop="20dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:maxLines = "10"
            android:text="@string/txtOut"
            android:scrollbars = "vertical"
            android:freezesText="true"
            android:background="@drawable/border"
            android:padding="10dip" />
    </RelativeLayout>
</HorizontalScrollView>        
于 2013-07-02T17:15:43.277 回答