![](/img/trans.png)
[英]Android GridView imperfection, how to remove extra white space to the right
[英]How to remove extra space in a gridview cell - Android
我正在android studio中创建自定义网格视图,每个单元格都包含一个图像视图和一个文本视图,但是它在顶部和图像之间以及图像和文本之间提供了额外的空间,请参见图片 。 我想摆脱多余的空间,但是我不知道解决方案!
这是项目(单元)布局的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:weightSum="5">
<ImageView
android:id="@+id/picture"
style="@style/Pic" />
<TextView
android:id="@+id/label"
style="@style/Text" />
这是我的主要布局的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary">
<TextView
style="@style/Main_Text"
android:text="@string/Main_Menu"/>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/gridView"
android:numColumns="3"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp"/>
删除weightsum,然后在您的imageview中添加
android:adjustViewBounds="true"
android:scaleType="fitXY"
如果要使用weightsum,请尝试为imageview和textview添加layoutweight
尝试实现
android:adjustViewBounds="true"
从您的代码中删除“ android:verticalSpacing =“ 0dip”,或者您可以尝试使用此代码,
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mGridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:cacheColorHint="@android:color/transparent"
android:columnWidth="40dip"
android:horizontalSpacing="0dip"
android:numColumns="auto_fit"
android:scrollbars="none"
android:verticalSpacing="0dip" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.