【发布时间】:2020-04-11 07:08:48
【问题描述】:
我有使用 GridLayoutManager 和 RecyclerView 的网格视图 如您所见,网格有 3 行工作正常,[![在此处输入图像描述][1]][1]
但由于某种原因,图像视图比例类型不适用于任何项目,并且您看到的那些项目工作正常,因为分辨率已经是平方平均值 512*512 但如果您看到最后一个分辨率较低的项目左右各有空格。
这是我的设置列表中的代码
int getori = getResources().getConfiguration().orientation;
if (getori == Configuration.ORIENTATION_PORTRAIT) {
gl = new GridLayoutManager(getBaseContext(), 3);
} else if (getori == Configuration.ORIENTATION_LANDSCAPE){
gl = new GridLayoutManager(getBaseContext(), 6);
}
gg.setHasFixedSize(true);
gg.setFitsSystemWindows(true);
gg.setLayoutManager(gl);
gg.setAdapter(startpostsystem);
这是我的网格适配器代码
@Override
public void onBindViewHolder(Grid_view holder, final int position) {
holder.im.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String getfiledop = fall[position].getAbsolutePath();
Intent is = new Intent(cm,Open_post_item.class);
is.putExtra("req",12);
cm.startActivity(is);
这是我的网格视图项目布局代码。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="140dp">
<ImageView
android:id="@+id/imageView18"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:adjustViewBounds="true"
app:srcCompat="@drawable/sunbow100" />
我尝试使用: android:scaleType="centerCrop" 机器人:adjustViewBounds =“真” 或者 fitxy 让它变得更糟 视图边界也不起作用。
如果我添加更多图像,例如 800*400 或...它将有空白
那么问题出在哪里我做错了。
【问题讨论】:
-
您尝试过使用
android:scaleType="fitXY"吗? -
@Biscuit 是的,它使情况变得更糟,并且破坏了其他在 centercrop 中显示良好的图像
标签: java android xml list android-recyclerview