使垂直滚动条可见

Rag*_*har 20 android scrollview textview

我想让垂直滚动条永久可见.目前滚动条仅在我尝试滚动滚动视图中包含的文本视图时出现.这是我的XML声明.

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@id/radio_group"
    android:layout_margin="5dp"
    android:scrollbars="vertical" 
    android:scrollbarAlwaysDrawVerticalTrack="true" >
    <TextView
        android:id="@+id/question"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:textColor="#FF000000"
        android:textStyle="bold" />
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

感谢您的时间.

jjb*_*jjb 42

您可以android:fadeScrollbars="false"在ScrollView XML中进行设置.


小智 5

我们可以通过 2 种不同的方式来完成,如下所示。

方法 1:在您的 XML 中

android:scrollbars="vertical"

android:fadeScrollbars="false"
Run Code Online (Sandbox Code Playgroud)

方法 2:在您的 Java 代码中

editText.setVerticalScrollBarEnabled(true);

editText.setVerticalscrollbarFading(false);
Run Code Online (Sandbox Code Playgroud)

  • 我收到此错误:`java.lang.NullPointerException: Attempt to invoke virtual method 'android.widget.ScrollBarDrawable android.widget.ScrollBarDrawable.mutate()' 在空对象引用上` (5认同)