以下是我的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使文本以水平布局显示。但是水平滚动在水平视图中仍然不起作用。 我怎样才能使它发挥作用?
答案 0 :(得分: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>