HorizontalScrollView基本用法
HorizontalScrollView是水平滚动标签。垂直滚动动是 ScrollView标签。
这里有一个需要注意的是这两个标签都只能包含一个子节点,如果写多个子节点系统会直接闪退掉。
这是使用这个标签需要注意的。
直接看测试源码
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <HorizontalScrollView android:layout_width="wrap_content" android:layout_height="300dp" android:background="#2196F3" android:scrollbars="none" android:overScrollMode="never" android:fadeScrollbars="false" > <LinearLayout android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="horizontal" > <View android:layout_width="300dp" android:layout_height="match_parent" android:background="#F44336" /> <View android:layout_width="300dp" android:layout_height="match_parent" android:background="#00BCD4" /> </LinearLayout> </HorizontalScrollView> </LinearLayout>
这样是实现了一个简单的水平滚动
去掉默认的滚动条还有两端拖动的装饰:
可以直接在XML源码里面设置
android:scrollbars="none"
android:overScrollMode="never"
即可。
也可以通过JAVA来设置,看一下java源码部分:
HorizontalScrollView horizontalScrollView = findViewById(R.id.hscroll); horizontalScrollView.setOverScrollMode(ScrollView.OVER_SCROLL_NEVER); horizontalScrollView.setHorizontalScrollBarEnabled(false);
实现的效果跟在XML里面设置是一样的。
分类:
android
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!