ScrollView在Android编程中不起作用
我试着学习Android编程。但是我被困在ScrollView一章。当我运行代码时,滚动功能不起作用 这是我的代码:ScrollView在Android编程中不起作用,android,scroll,scrollview,Android,Scroll,Scrollview,我试着学习Android编程。但是我被困在ScrollView一章。当我运行代码时,滚动功能不起作用 这是我的代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wra
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/splash"
android:orientation="vertical" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="225dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button4" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button5" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button6" />
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button7" />
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button8" />
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button9" />
<Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button10" />
<Button
android:id="@+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button11" />
</LinearLayout>
</ScrollView>
</LinearLayout>
当我在加载代码后立即运行代码时,我看到了滚动条,但它立即消失
谁能帮帮我吗
谢谢。我想这是因为您已设置了滚动视图的高度,只需删除此项并将其设置为
包装内容
,然后重试
所以基本上要换掉这条线
<ScrollView
android:layout_width="fill_parent"
android:layout_height="225dp" >
与
然后再试。尝试如下更改您的xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/splash"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button2" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button3" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button4" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button5" />
<Button
android:id="@+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button6" />
<Button
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button7" />
<Button
android:id="@+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button8" />
<Button
android:id="@+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button9" />
<Button
android:id="@+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button10" />
<Button
android:id="@+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button11" />
</LinearLayout>
</ScrollView>
尝试设置属性
android:fadeScrollbars=“false”
,该属性将使指示器始终可见,即使您不触摸它
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="false">
我想这就是你想要的 你说它消失是什么意思?当你触摸滚动区域时,滚动将显示,当你离开滚动区域时,滚动将消失。这是android滚动视图的默认行为。你到底想要什么?不要给出固定的滚动视图高度。只需使用wrap_content或match_parent进行更改。您的意思是说,当您左键触摸滚动条时,滚动指示器不可见@拉胡尔
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="false">