Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 不需要的栅格视图间距_Android_Android Imageview_Textview_Android Gridview - Fatal编程技术网

Android 不需要的栅格视图间距

Android 不需要的栅格视图间距,android,android-imageview,textview,android-gridview,Android,Android Imageview,Textview,Android Gridview,我的网格设计就是这样。但是我想删除网格元素两侧的空格。(黑色标记) 我希望图像可以像这样展开 gridview的我的XML布局 <?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:l

我的网格设计就是这样。但是我想删除网格元素两侧的空格。(黑色标记)

我希望图像可以像这样展开

gridview的我的XML布局

<?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>

我的网格元素布局

<?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>

尝试更改

 <GridView
        android:id="@+id/grid"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:verticalSpacing="1dp"
        android:horizontalSpacing="1dp"
        android:numColumns="2"
        android:background="#abcdef"
        android:stretchMode="columnWidth" />


您可以将GridView替换为GridLayout,并使用权重使图像填满屏幕。以下是参考资料:,(请参阅“多余空间分布”一节)

有效,是否有办法在列之间引入分隔符,如直线或薄空间。您可以做的是将背景颜色设置为gridview,并将垂直和水平间距设置为
1dp
,我已更新了我的答案,但是在左边没有间隔(我已经更新了图片)。此外,我想不仅水平地扩展图像,而且像扩展正方形那样,使其看起来不失真