2014-09-20 215 views
0

我尝试从BaseAdapter向我的元素应用边距。我尝试了几件事。我有点失望,我不能只为我的drawable.xml“背景”添加边距。BaseAdapter元素边距

(活动 - 布局)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> 

(绘制对象)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> 

编辑: 它看起来像这样:

enter image description here

我想每一个 “项目” 分开。

+0

究竟是什么问题?只需为每个“视图”应用一个保证金即可。 – 2014-09-20 08:54:00

回答

1

要将填充添加到drawable中,可以将其包装在inset中。

+0

谢谢:) 我把包在里面,并加入了insets-attributes!这工作! – codepleb 2014-09-20 09:12:29