【发布时间】:2016-06-04 00:48:06
【问题描述】:
如何将垂直回收器视图放入水平滚动视图?
adapter在viewholder绑定数据时,增加item的左边距。
(例如:leftMargin = 位置 * 100)
但水平滚动视图不起作用。
帮帮我~~
对不起,我的英语不好。
我的活动布局.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbarAlwaysDrawHorizontalTrack="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
和 list_item .xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_margin="8dp"
card_view:cardCornerRadius="2dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/bullet" />
<CheckBox
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
【问题讨论】:
-
为什么要把recycleView放在horrizontalScroll里面?您可以通过使用 RecycleView 来实现另一个目标并使其水平。
-
谢谢我试试。我认为您的解决方案需要两个适配器。我可以得到更简单的方法吗?
标签: android