2012-11-09 202 views
0

我想使用SimpleAdapter,並且不想覆蓋Adapter。它是通過編寫ListView佈局文件實現的,並讓圖像在上傳後顯示圓邊。我找到了一些參考,並像這樣編寫代碼。我不明白如何傳遞參數。任何人的正確方向是感恩。Android-如何在列表視圖中顯示圖像圓邊緣

adapter.setViewBinder(new ViewBinder() { 
    public boolean setViewValue(View view, Object data, 
      String textRepresentation) { 

     if(view instanceof ImageView && data instanceof Bitmap){ 
      ImageView iv = (ImageView) view; 

      iv.setImageBitmap((Bitmap) data); 
      return true; 
     }else 
     return false; 
    } 
}); 

回答

1

使用該標籤創建帶圓角的XML的繪圖。 (你也可以用形狀標籤來做其他事情,比如定義一個顏色漸變)。

下面是我用我的應用程序之一,創建一個白色背景,黑色的邊框和圓角的繪製一個XML文件的副本:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#ffffffff"/>  

    <stroke android:width="3dp" 
      android:color="#ff000000" 
      /> 

    <padding android:left="1dp" 
      android:top="1dp" 
      android:right="1dp" 
      android:bottom="1dp" 
      /> 

    <corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" 
    android:topLeftRadius="7dp" android:topRightRadius="7dp"/> 
</shape> 
+0

非常感謝,但如何使用XML文件上傳圖片? –

+0

將其另存爲可拉伸文件夾內的xml。並將您的imageview的背景設置爲R.drawable.your_xml_file – san

相關問題