Android Grdiview 显示不正确
Android Grdiview not displaying correctly
我们已经构建了一个在线购物应用程序。
我们有两种 gridview 布局。
第一个:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
tools:context=".HomeActivity">
<GridView
android:id="@+id/gridView"
android:numColumns="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</RelativeLayout>
每个 gridview 单元格的第二个:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/singleCell"
android:layout_width="345px"
android:layout_height="400px"
android:background="#E6E6E6">
<ImageView
android:contentDescription="@string/hello_world"
android:id="@+id/profileImg"
android:layout_width="fill_parent"
android:layout_height="330px"
android:scaleType="fitXY"
android:layout_marginLeft="1px"
android:layout_marginTop="2px"/>
<TextView
android:id="@+id/friend_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Name"
android:textColor="#000000"
android:textStyle="bold"
android:layout_marginTop="340px"
android:layout_marginLeft="20px"
android:textSize="13sp">
</TextView>
</FrameLayout>
问题是在某些设备上gridview是这样正确显示的,而且比例没问题。
gridview is displayed correctly on some devices
但在其他几个设备中,图像高度和比例发生变化,图像显示不正确。
gridview is displayed incorrectly on some devices
如果您给我们一个解决方案并帮助我们,我们将很高兴。这是一个关键问题,因为网格单元图像高度会发生变化,并且在某些设备中会变长。
您可以尝试更改Imageview 的缩放类型。写这一行
android:scaleType="centerCrop"
而不是
android:scaleType="fitXY"
@nazmul-hasan-masum,谢谢。我使用了您的解决方案,但起初问题没有得到解决,所以我将图像视图和文本单位从 px 更改为等效的 dp,现在一切正常。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/singleCell"
android:layout_width="345px"
android:layout_height="400px"
android:background="#E6E6E6">
<ImageView
android:contentDescription="@string/hello_world"
android:id="@+id/profileImg"
android:layout_width="fill_parent"
android:layout_height="128dp"
android:scaleType="centerCrop"
android:layout_marginLeft="1px"
android:layout_marginRight="1px"
android:layout_marginTop="2px"/>
<TextView
android:id="@+id/friend_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Name"
android:textColor="#000000"
android:textStyle="bold"
android:layout_marginTop="130dp"
android:layout_marginLeft="20px"
android:textSize="13sp">
</TextView>
</FrameLayout>
我们已经构建了一个在线购物应用程序。
我们有两种 gridview 布局。 第一个:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
tools:context=".HomeActivity">
<GridView
android:id="@+id/gridView"
android:numColumns="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</RelativeLayout>
每个 gridview 单元格的第二个:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/singleCell"
android:layout_width="345px"
android:layout_height="400px"
android:background="#E6E6E6">
<ImageView
android:contentDescription="@string/hello_world"
android:id="@+id/profileImg"
android:layout_width="fill_parent"
android:layout_height="330px"
android:scaleType="fitXY"
android:layout_marginLeft="1px"
android:layout_marginTop="2px"/>
<TextView
android:id="@+id/friend_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Name"
android:textColor="#000000"
android:textStyle="bold"
android:layout_marginTop="340px"
android:layout_marginLeft="20px"
android:textSize="13sp">
</TextView>
</FrameLayout>
问题是在某些设备上gridview是这样正确显示的,而且比例没问题。
gridview is displayed correctly on some devices
但在其他几个设备中,图像高度和比例发生变化,图像显示不正确。
gridview is displayed incorrectly on some devices
如果您给我们一个解决方案并帮助我们,我们将很高兴。这是一个关键问题,因为网格单元图像高度会发生变化,并且在某些设备中会变长。
您可以尝试更改Imageview 的缩放类型。写这一行
android:scaleType="centerCrop"
而不是
android:scaleType="fitXY"
@nazmul-hasan-masum,谢谢。我使用了您的解决方案,但起初问题没有得到解决,所以我将图像视图和文本单位从 px 更改为等效的 dp,现在一切正常。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/singleCell"
android:layout_width="345px"
android:layout_height="400px"
android:background="#E6E6E6">
<ImageView
android:contentDescription="@string/hello_world"
android:id="@+id/profileImg"
android:layout_width="fill_parent"
android:layout_height="128dp"
android:scaleType="centerCrop"
android:layout_marginLeft="1px"
android:layout_marginRight="1px"
android:layout_marginTop="2px"/>
<TextView
android:id="@+id/friend_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Name"
android:textColor="#000000"
android:textStyle="bold"
android:layout_marginTop="130dp"
android:layout_marginLeft="20px"
android:textSize="13sp">
</TextView>
</FrameLayout>