在Android手机上更改字体大小后,在textView中启用滚动条

时间:2015-10-06 15:34:32

标签: java android xml

当我在设备上放大字体并且之后我不再在textview中看到Vertical Scrollbar时,会发生此问题。当我将字体大小更改为小时,会出现滚动条。这是我的xml布局的样子:

  1.             <ScrollView
                    android:id="@+id/MyScrollView"
                    android:layout_height="150px"
                    android:layout_width="fill_parent">
                <TextView
                    android:id="@+id/title"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"  android:text="xxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasd."
                    android:textSize="24sp"
                    android:layout_margin="20dp"
                    android:ellipsize="marquee"
                    android:marqueeRepeatLimit="marquee_forever"
                    android:maxLines = "20"
                    android:gravity="bottom"
                    android:scrollbars="vertical"
                    android:scrollbarStyle="insideOverlay"
                    android:textColor="#676767" />
                <TextView
                    android:id="@+id/tv_link"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/tv_title"
                    android:layout_centerHorizontal="true"
                    android:layout_margin="5dp"
                    android:padding="5dp"
                    android:textSize="24sp"
                    android:text="Enroll Now"
                    android:textColor="#FF0C7CC0" />
                </ScrollView>
    

    代码工作正常,但只要我在设备上更改了字体大小,滚动条就会消失

    1. 以下是我在Activity类中所做的事情:

          ScrollView scroller = (ScrollView) findViewById(R.id.ScrollView01);
          TextView tv = (TextView) findViewById(R.id.title);
          tv.setMovementMethod(new ScrollingMovementMethod());
      

1 个答案:

答案 0 :(得分:0)

应该有一个包含你的textview的布局,scrollview无法直接控制多个视图。 Scrollview只能包含单个视图,您可以这样做:

  <ScrollView
                android:id="@+id/MyScrollView"
                android:layout_height="150px"
                android:layout_width="fill_parent">
          <RealtiveLayout
               android:layout_width="wrap_content"
                android:layout_height="wrap_content">
            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"  android:text="xxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasdxxasdasdasd."
                android:textSize="24sp"
                android:layout_margin="20dp"
                android:ellipsize="marquee"
                android:marqueeRepeatLimit="marquee_forever"
                android:maxLines = "20"
                android:gravity="bottom"
                android:scrollbars="vertical"
                android:scrollbarStyle="insideOverlay"
                android:textColor="#676767" />
            <TextView
                android:id="@+id/tv_link"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/title"
                android:layout_centerHorizontal="true"
                android:layout_margin="5dp"
                android:padding="5dp"
                android:textSize="24sp"
                android:text="Enroll Now"
                android:textColor="#FF0C7CC0" />
</RealtiveLayout>
            </ScrollView>