横向滑动item

要在NestedScrollView中实现横向滑动,可以将横向滑动的内容放在HorizontalScrollView中,然后将HorizontalScrollView作为NestedScrollView的子视图。具体步骤如下: 1. 在布局文件中,将NestedScrollView作为父布局,设置android:orientation="vertical"。 2. 在NestedScrollView中添加HorizontalScrollView作为子视图,设置android:orientation="horizontal"。 3. 在HorizontalScrollView中添加横向滑动的内容,例如若干个TextView。 4. 在代码中,使用setNestedScrollingEnabled(false)方法禁用NestedScrollView的滑动事件,使得HorizontalScrollView可以接收滑动事件。 下面是一个示例代码: ``` <androidx.core.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Horizontal item 1"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Horizontal item 2"/> <!-- 添加更多的TextView --> </LinearLayout> </HorizontalScrollView> </androidx.core.widget.NestedScrollView> ``` 在代码中,添加如下语句: ``` HorizontalScrollView horizontalScrollView = findViewById(R.id.horizontal_scroll_view); horizontalScrollView.setNestedScrollingEnabled(false); ``` 这样就可以在NestedScrollView中实现横向滑动了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值