android-如何根据屏幕尺寸设置回收站视图项目的宽度尺寸?

前端之家收集整理的这篇文章主要介绍了android-如何根据屏幕尺寸设置回收站视图项目的宽度尺寸? 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我想让我的RecyclerView项目的宽度和高度相等,并根据屏幕大小动态更改其大小吗?

我该如何处理任何建议或示例代码

这是我的代码

@H_301_9@ 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); @H_502_11@

这是我的适配器:

@H_301_9@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; } @H_502_11@

和我的回收商项目xml一样:

@H_301_9@<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> @H_502_11@
最佳答案
请在recyclerview项目中使用ConstraintLayout..约束已更新,并且比相对和线性布局好..约束布局将根据屏幕自动调整…

猜你在找的Android相关文章