我正在尝试创建类似于Google Play中使用的卡片的网格布局
我正在使用的布局和获得的布局是:
对于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"
tools:context=".MainActivity"
android:background="#e5e5e5"
>
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="60dp"
android:numColumns="2"
android:layout_marginLeft="2dp"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
</RelativeLayout>
for GridItem:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_card"
>
<ImageView
android:id="@+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:textSize="17sp"
android:layout_below="@id/imgIcon"
android:layout_marginTop="35dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
我得到的输出是:
我使用的图像尺寸为356x500。 (我确实使用300x300获得了一个尺寸稍大的网格) 我面临的问题是:
请帮我纠正这个问题。 感谢
答案 0 :(得分:0)
空间是因为你使用了
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
同时编辑
<ImageView
android:id="@+id/imgIcon"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
在gridview中使用机器人:stretchMode =&#34;无&#34;而不是android:stretchMode =&#34; columnWidths#34;
答案 1 :(得分:0)
把android:scaleType =&#34; fitStart&#34;在你的
里面答案 2 :(得分:0)
使用imgIcon.setAdjustViewBounds(true);
你也可以在xml