RecyclerView Horizontal Scrollview example 如何创建水平recyclerview?水平滚动视图示例
RecyclerView Horizontal Scrollview example How to create horizontal recyclerview ? Horizontal scrollview example
如何使用回收器视图为 Features 和 Rules 下的元素创建水平滚动?
我知道对于 属性 类型 和 房间数量 我可以使用两个单独的回收站视图。但是,我是否需要创建两个回收器视图来显示这些元素,因为文本元素的长度将不均匀,并且如果添加更多规则和功能,以满足不断扩展的项目列表?
You can create a horizontal scrollview by doing this ie set horizontal
layout manager
recyclerViewTeams.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
示例代码
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewProperty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp" />
在 Java class
private RecyclerView recyclerViewProperty;
recyclerViewProperty = (RecyclerView) view.findViewById(R.id.recyclerViewProperty);
recyclerViewTeams.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
public class TeamsAdapter 扩展 RecyclerView.Adapter {
ArrayList<TeamsListingModal> arrayList;
private Activity mContext;
private int selected_position;
private boolean isSelected = false;
public class MyView extends RecyclerView.ViewHolder {
public TextView textview;
private RelativeLayout parentLayout;
public MyView(View view) {
super(view);
parentLayout = (RelativeLayout) view.findViewById(R.id.parentLayout);
textview = (TextView) view.findViewById(R.id.textview);
}
}
public TeamsAdapter(Activity activity, ArrayList<CustomModal> arrayList) {
this.mContext = activity;
this.arrayList = arrayList;
}
@Override
public MyView onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.property_adapter_item, parent, false);
return new MyView(itemView);
}
@Override
public void onBindViewHolder(final MyView holder, final int position) {
//inflate views here
}
@Override
public int getItemCount() {
return arrayList.size();
}
}
和xml这里property_adapter_item
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/parentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/textView"
android:layout_width="70dp"
android:layout_height="70dp"
app:border_width="5dp" />
</RelativeLayout>
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
In Kotlin Horizontal Scroolview in RecyclerView: - We use this Code
recycler_upcoming.layoutManager =
LinearLayoutManager(sContext, LinearLayoutManager.HORIZONTAL, false)
recycler_upcoming.adapter =
InboxUpcomingAdapter(list, sContext)
-> sContext mean Ur Context
-> If you pass false then scroll right to left
-> If You pass true then scroll left to right
如何使用回收器视图为 Features 和 Rules 下的元素创建水平滚动?
我知道对于 属性 类型 和 房间数量 我可以使用两个单独的回收站视图。但是,我是否需要创建两个回收器视图来显示这些元素,因为文本元素的长度将不均匀,并且如果添加更多规则和功能,以满足不断扩展的项目列表?
You can create a horizontal scrollview by doing this ie set horizontal layout manager
recyclerViewTeams.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
示例代码
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewProperty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp" />
在 Java class
private RecyclerView recyclerViewProperty;
recyclerViewProperty = (RecyclerView) view.findViewById(R.id.recyclerViewProperty);
recyclerViewTeams.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
public class TeamsAdapter 扩展 RecyclerView.Adapter {
ArrayList<TeamsListingModal> arrayList;
private Activity mContext;
private int selected_position;
private boolean isSelected = false;
public class MyView extends RecyclerView.ViewHolder {
public TextView textview;
private RelativeLayout parentLayout;
public MyView(View view) {
super(view);
parentLayout = (RelativeLayout) view.findViewById(R.id.parentLayout);
textview = (TextView) view.findViewById(R.id.textview);
}
}
public TeamsAdapter(Activity activity, ArrayList<CustomModal> arrayList) {
this.mContext = activity;
this.arrayList = arrayList;
}
@Override
public MyView onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.property_adapter_item, parent, false);
return new MyView(itemView);
}
@Override
public void onBindViewHolder(final MyView holder, final int position) {
//inflate views here
}
@Override
public int getItemCount() {
return arrayList.size();
}
}
和xml这里property_adapter_item
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/parentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">
<TextView
android:id="@+id/textView"
android:layout_width="70dp"
android:layout_height="70dp"
app:border_width="5dp" />
</RelativeLayout>
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
In Kotlin Horizontal Scroolview in RecyclerView: - We use this Code
recycler_upcoming.layoutManager =
LinearLayoutManager(sContext, LinearLayoutManager.HORIZONTAL, false)
recycler_upcoming.adapter =
InboxUpcomingAdapter(list, sContext)
-> sContext mean Ur Context
-> If you pass false then scroll right to left
-> If You pass true then scroll left to right