android - Gridview 元素对齐

标签 android gridview android-imageview textview

我现在的设计截图

enter image description here

但我希望设计类似于下面的设计

enter image description here

网格布局如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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" >

    <GridView
        android:id="@+id/grid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:columnWidth="100dip"
        android:gravity="center"
        android:numColumns="2"
        android:stretchMode="spacingWidthUniform" />

</LinearLayout>

单个gridview元素布局如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/grid_image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:contentDescription="@string/im" >
    </ImageView>

    <TextView
        android:id="@+id/grid_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxLength="23"
        android:gravity="center"
        android:layout_marginTop="10sp"
        android:textSize="12sp" >
    </TextView>

</LinearLayout>

enter image description here

最佳答案

试试这个

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/grid_image"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:contentDescription="@string/im" >
    </ImageView>

    <TextView
        android:id="@+id/grid_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:maxLength="23"
        android:gravity="center"
        android:layout_marginTop="10sp"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:textSize="12sp" >
    </TextView>

</LinearLayout>

关于android - Gridview 元素对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31370513/

相关文章:

android - 在 Android Gridview 中显示复合项目

android - ImageView 有过多的垂直填充

android - 如何加快 Xamarin Android 中的 SPP 吞吐量?

android - 如何以编程方式关闭应用程序?

android - 如何找到从android中的Assets文件夹中读取的pdf的最后一页

android - 我们能否像监控信标(进入区域、退出区域)一样监控 BLE 服务?

css - 选择响应式/流体网格框架/模板

javascript - 我想在右键单击时创建 oncontextmenu 事件

android - 无法更改 ImageView 的可见性

android - 带背景的旋转图像抗锯齿?