2013-11-21 100 views
0

我有一個圖像的列表視圖,我似乎無法從垂直項目之間獲得額外的間距。嘗試了很多東西,但迄今沒有運氣。我似乎無法弄清楚間距是從哪裏來的。listview項目之間的額外間距

下面是一個包含ListView控件的XML(這是這並拖動/排序自定義列表視圖)

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
    android:id="@+id/fan_ban_ctn" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.1" 
    android:background="@color/white" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/fan_button" 
     style="?android:attr/borderlessButtonStyle" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_gravity="left|center_vertical" 
     android:layout_weight="0.33" 
     android:text="@string/fan" 
     android:textSize="14sp" /> 

    <Button 
     android:id="@+id/ban_button" 
     style="?android:attr/borderlessButtonStyle" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center_vertical|center_horizontal" 
     android:layout_weight="0.33" 
     android:text="@string/ban" 
     android:textSize="14sp" /> 

    <Button 
     android:id="@+id/ctn_button" 
     style="?android:attr/borderlessButtonStyle" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_gravity="right|center_vertical" 
     android:layout_weight="0.33" 
     android:text="@string/ctn" 
     android:textSize="14sp" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/wireless_mgmt" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.9" 
    android:background="@color/white" 
    android:orientation="horizontal" 
    android:weightSum="1.0" > 

    <com.att.attbusiness.widget.DynamicListView 
     android:id="@+id/widget_list" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.10" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="2dp"/> 

    <ScrollView 
     android:id="@+id/widget_content" 
     android:layout_width="0dp" 
     android:layout_height="fill_parent" 
     android:layout_marginRight="12dp" 
     android:layout_weight="0.85" 
     android:background="@color/white" > 

     <FrameLayout 
      android:id="@+id/wireless_fragment_Container" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 
    </ScrollView> 
</LinearLayout> 

和列表項是在這裏:

<ImageView 
    android:id="@+id/widget_btn" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/wm_plan" /> 

當我編程自定義Adaper中加入其他ImageViews,我得到這個 的結果: enter image description here

我怎樣才能減少圖像之間的距離?

雖然我以編程方式向listview添加圖像,但我不做任何佈局或邊距或任何東西 - 只是圖像。但是,我的確看到了一些不同的圖像。我正在使用一些字符串操作構建的資源ID加載並將位圖分配給ArrayLists。我有一個選定和未選擇的版本,每個都是相同的大小。

private final static String[] widgetNames = new String[] { 
    "wm_device", "wm_userinfo", "wm_billing", "wm_plan", "wm_features", "wm_access_options", "wm_applications", 
    "wm_analytics", "wm_manage_a_list" 
}; 

<...> 

for (int i = 0; i < widgetNames.length; ++i) { 
     int normalID = this.getResources().getIdentifier(widgetNamesOrdered[i], "drawable", "com.att.attbusiness"); 
     int selectID = this.getResources().getIdentifier(widgetNamesOrdered[i]+"_selected", "drawable", "com.att.attbusiness"); 
     mWidgetList.add(widgetNamesOrdered[i]);   

     if (normalID != 0) { 
      widgetIcons.add(i, (Bitmap) BitmapFactory.decodeResource(this.getResources(), normalID)); 
     }   

     if (selectID != 0) { 
      widgetIconsSelected.add(i, (Bitmap) BitmapFactory.decodeResource(this.getResources(), selectID)); 
     } 


    } 

下面是設置在ListView像我的自定義適配器的部分:在你的XML文件layout_marginTop = 「0dp」:

// if this button isn't the selected, make sure it's off 
     if(mSelectedPosition != position){ 

      holder.widget.setImageBitmap(widgetIcons.get(position)); 
     } 
     else { 
      holder.widget.setImageBitmap(widgetIconsSelected.get(position)); 
      if(mSelectedBtn != null && holder.widget != mSelectedBtn){ 
       mSelectedBtn = holder.widget; 
      } 
     } 
+0

顯示創建ImageView並以編程方式將其添加到代碼中。 – Devrim

+0

在我的自定義適配器 – Martin

+0

中添加了我的getView()部分,您是否嘗試將您的LinearLayouts設置爲layout_height =「wrap_content」?,特別是包含ListView – CSmith

回答

0

你嘗試過的Android?否則,我只需要使用listview而不是linearlayout

+0

的頂部和底部邊距設置爲負值時,當我僅僅把圖像放入列表中時,我不得不這樣做。 – Martin

+0

我明白了,但由於您實際上是在java文件而不是xml(您有線性佈局)中構建列表,所以它是最佳解決方案。 – user2383106

+0

另一種可能性是您希望您的列表重疊,因爲它們內部的內容不佔用整個區域 – user2383106