我正在使用交错网格布局管理器在我的应用程序中设置交错网格,我在“卡片 View ”中使用了 Imageview。交错效果正常工作,但在某些情况下,当图像尺寸太大时,布局将是像这样
[![在此处输入图片描述][1]][1]
我的xml文件
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="220dp"
android:layout_height="180dp"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="8dp"
android:layout_marginBottom="16dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/country_photo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@string/action_settings"
android:src="@drawable/three"
android:scaleType="centerCrop" />
<ImageView
android:id="@+id/outside_imageview"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
android:src="@drawable/varified"
android:layout_alignBottom="@id/country_photo"
android:layout_alignRight="@id/country_photo"
android:scaleType="fitEnd" />
</RelativeLayout>
卡片 View 的宽度为 220dp,高度为 180dp, ImageView 宽度 = "match_parent"和高度 = "wrap_content"缩放类型也为 centerCrop,这适用于小尺寸图像。布局将是像下面的屏幕截图,如果是大尺寸图像。如何解决这个问题??
在小型设备上的 View 如下所示
最佳答案
为大屏幕布局、普通屏幕布局和小屏幕布局等设置不同的列数。使用此代码以编程方式检查设备屏幕尺寸。
public void checkScreenSize()
{
int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
String toastMsg;
switch (screenSize) {
case Configuration.SCREENLAYOUT_SIZE_XLARGE:
toastMsg = "XLarge screen";
//set action
break;
case Configuration.SCREENLAYOUT_SIZE_UNDEFINED:
toastMsg = "XLarge screen";
//set action
break;
case Configuration.SCREENLAYOUT_SIZE_LARGE:
toastMsg = "Large screen";
//set action
break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
toastMsg = "Normal screen";
//set action
break;
case Configuration.SCREENLAYOUT_SIZE_SMALL:
//set action
toastMsg = "Small screen";
break;
default:
toastMsg = "Screen size is neither large, normal or small";
}
关于android - 如何在不同的屏幕尺寸下设置交错网格布局。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31988315/