我尝试从BaseAdapter向我的元素应用边距。我尝试了几件事。我有点失望,我不能只为我的drawable.xml“背景”添加一个边距。
(活动 - 布局)ItemsView.xml
<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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.nubage.minepedia.ItemsView">
<GridView
android:id="@+id/gridView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="80dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"/>
</RelativeLayout>
(布局)item_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp"
android:background="@drawable/single_item">
<ImageView
android:id="@+id/imageView"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_horizontal">
</ImageView>
<TextView
android:id="@+id/lastSyncTextView"
android:layout_width="70dp"
android:layout_height="62dp"
android:textSize="13sp"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal">
</TextView>
</LinearLayout>
(Drawable)single_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#88000000">
</solid>
<stroke
android:width="2dp"
android:color="#444444" >
</stroke>
<corners
android:radius="2dp" >
</corners>
</shape>
修改 它看起来像这样:
我想分开每个“项目”。