Android GridView 中的网格填充
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12247309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Padding of grid in GridView
提问by alwx
I have some problems with my grid layout.
我的网格布局有一些问题。
<?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:id="@+id/frag_books_grid_view_layout"
android:orientation="vertical">
<GridView
android:padding="0dp"
android:cacheColorHint="@color/bg_default"
android:listSelector="@drawable/list_selector_background"
android:id="@+id/frag_books_grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchMode="spacingWidth"
android:scrollbars="none"/>
</LinearLayout>
Single item:
单品:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:cacheColorHint="@color/bg_default"
android:scrollbars="none"
android:listSelector="@drawable/list_selector_background"
android:layout_gravity="center_vertical|left"
android:gravity="center_vertical|left"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:id="@+id/frag_book_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="5dp"/>
</LinearLayout>
Problem is that there is no left and right padding of single item. And it looks terrible when item is selected: http://i.imgur.com/rirNP.png
问题是单项没有左右填充。选择项目时看起来很糟糕:http: //i.imgur.com/rirNP.png
Please, help to fix it.
请帮助修复它。
回答by Mohammod Hossain
try it
尝试一下
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu_category"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
for information
信息
http://developer.android.com/guide/topics/ui/layout/gridview.html
http://developer.android.com/guide/topics/ui/layout/gridview.html
回答by Mohammod Hossain
this one is best for three columns..
这个最适合三列..
<GridView
android:id="@+id/gridview_Gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="65dp"
android:gravity="center"
android:horizontalSpacing="6dp"
android:listSelector="#00000000"
android:numColumns="3"
android:scrollbars="none"
android:stretchMode="columnWidth"
android:verticalSpacing="-1dp" />