我想让我的RecyclerView项目的宽度和高度相等,并根据屏幕大小动态更改其大小吗?
我该如何处理任何建议或示例代码?
这是我的代码:
mrv = findViewById(R.id.rv_segments);
list = new ArrayList<>();
mAdapter = new SegmentsAdapter(this,list,station.getWidthCount());
//mAdapter.setOnItemClickListener(this);
mLayoutManager = new LinearLayoutManager(getApplicationContext());
mLayoutManager = new GridLayoutManager(getActivity(),station.getWidthCount());
mrv.setLayoutManager(mLayoutManager);
mrv.setAdapter(mAdapter);
这是我的适配器:
public SegmentsAdapter.BaseHolder onCreateViewHolder(ViewGroup parent,int viewType) {
View view1 = LayoutInflater.from(context).inflate(R.layout.recyler_item_segments,parent,false);
BaseHolder viewHolder1 = new BaseHolder(view1);
return viewHolder1;
}
和我的回收商项目xml一样:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/custom_ln_border"
android:padding="2dp">
<LinearLayout
android:id="@+id/ln"
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="centerCrop"
android:orientation="horizontal"
android:background="@color/menu3"
/>
</LinearLayout>
最佳答案
请在recyclerview项目中使用ConstraintLayout..约束已更新,并且比相对和线性布局好..约束布局将根据屏幕自动调整…
原文链接:https://www.f2er.com/android/531366.html