kha*_*eer 5 android android-recyclerview
我需要这样的输出.这是HorizontalRecyclerView作为VerticalRecyclerView的标头.
目前我正在使用NestedScrollView来实现这种设计.但我觉得滚动不顺畅.
请提出任何想法.提前致谢.
布局:
<android.support.v4.widget.NestedScrollView
android:id="@+id/nsv_my_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="ifContentScrolls"
android:visibility="gone"
android:clipChildren="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="15dp">
<LinearLayout
android:id="@+id/ll_continue_watching"
android:layout_width="match_parent"
android:layout_height="132dp"
android:visibility="gone"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="29dp"
android:gravity="center_vertical"
android:paddingLeft="15dp"
android:paddingRight="15dp">
<customview.font.TextView
android:id="@+id/txt_edit_remove_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="@drawable/btn_profile_edit"
android:gravity="center"
android:paddingTop="2dp"
android:text="EDIT"
android:textSize="10sp" />
<customview.font.TextView
android:id="@+id/txt_continue_watchng"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:text="Continue watching"
android:textSize="12sp" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/horizontal_view_color" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_horizontal_view"
android:layout_width="match_parent"
android:layout_height="102dp"
android:paddingBottom="15dp"
android:paddingTop="15dp" />
<View
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="@color/horizontal_view_color" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_vertical_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
非常简单,您的“主”回收器视图有两种单元格,第一种是另一个回收器视图,其余的是“正常”单元格。
在“主”回收器视图的适配器上,您必须重写 getItemViewType 方法,如下所示:
@Override
public int getItemViewType(int position) {
if(postition == 0) {
return 1; //Let's say that you define that 1 is the view type for the recycler view cell
}
else {
return 2; //And 2 is going to be the "normal" cells
}
}
Run Code Online (Sandbox Code Playgroud)
然后,在 onCreateViewHolder 方法上,根据视图类型,您必须构建并返回正确的 viewHolder,如下所示:
@Override
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
if(viewType == 1) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.your_other_recyclerview_layout, parent, false);
//build the viewHolder
ViewHolder vh = new YourOtherRecyclerViewHolder(v);
return vh;
}
else {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.your_normal_cell_layout, parent, false);
//build the normal viewHolder
YourNormalViewHolder vh = new YourNormalViewHolder (v);
return vh;
}
}
Run Code Online (Sandbox Code Playgroud)
当然,您必须实现 2 个扩展 ViewHolder 类的类,一个用于 YourOtherRecyclerViewHolder,另一个用于 YourNormalViewHolder。
我希望它有帮助!
| 归档时间: |
|
| 查看次数: |
1052 次 |
| 最近记录: |