我在屏幕上有很多项目,我需要使用滚动条,以便用户可以向下滚动。然而,滚动要么不可见,要么不起作用。怎么可能添加一个滚动条到线性布局?
当前回答
您需要使用以下属性并将其包含在线性布局中
<LinearLayout ...>
<scrollView ...>
</scrollView>
</LinearLayout>
其他回答
你需要用滚动视图来包装你的线性布局
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
您需要使用以下属性并将其包含在线性布局中
<LinearLayout ...>
<scrollView ...>
</scrollView>
</LinearLayout>
无论何时你想让一个布局可滚动,你可以使用<ScrollView>与布局或组件在其中。
你需要把ScrollView作为布局文件的第一个子文件,现在把你的线性布局放在里面。现在,android将根据可用的内容和设备大小决定是否显示滚动。
确保线性布局没有兄弟,因为ScrollView不能有一个以上的子。
<LinearLayout
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:orientation="vertical"
tools:context=".MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<---------Content Here --------------->
</LinearLayout>
</ScrollView>
</LinearLayout>
推荐文章
- Android Studio, logcat在应用程序关闭后清理
- 在android中从上下文获取活动
- 无法解析主机"<URL here>"没有与主机名关联的地址
- getActivity()在Fragment函数中返回null
- 按钮背景是透明的
- 在Mac OS X上哪里安装Android SDK ?
- 我如何获得图像缩放功能?
- 在Android应用程序中显示当前时间和日期
- BottomSheetDialogFragment的圆角
- 在应用程序启动时出现“无法获得BatchedBridge,请确保您的bundle被正确打包”的错误
- 我如何改变默认对话框按钮的文本颜色在安卓5
- 更改单选按钮的圆圈颜色
- 如何在android中复制一个文件?
- adb找不到我的设备/手机(MacOS X)
- 如何在新的材质主题中改变背面箭头的颜色?