如何使用回收商视图为功能和规则下的元素创建水平滚动?
我知道对于属性类型和房间数,我可以使用两个单独的回收站视图。但是,我是否需要创建两个回收站视图来显示这些元素,因为如果添加更多规则和功能,文本元素的长度将不均匀并且可以满足不断扩展的项目列表的需要?
答案 0 :(得分:2)
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(linearLayoutManager);
答案 1 :(得分:1)
试试这个
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerViewProperty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp" />
在Java类
中 private RecyclerView recyclerViewProperty;
recyclerViewProperty = (RecyclerView) view.findViewById(R.id.recyclerViewProperty);
recyclerViewTeams.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
公共类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>
答案 2 :(得分:0)
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