2012-01-27 63 views
0

我不確定是否需要更改邊框的厚度或圖像周圍的邊距。我之前從未使用過樣式,並且第一次創建了styles.xml和colors.xml文件。我使用image_border.xml中的以下代碼將背景顏色更改爲紅色。但我不知道如何改變HelloGallery中圖像的邊框厚度。如何在HelloGallery中更改圖像周圍的邊框厚度

也許它不在這個文件中。但是,代碼中究竟需要寫些什麼呢?

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:top="1dp" android:left="1dp" 
     android:right="1dp" android:bottom="1dp"> 
     <shape android:shape="rectangle"> 
      <solid android:color="@color/red" /> 
     </shape> 
    </item> 
</layer-list> 

編輯:答案實際上可能是修改代碼的這個部分的問題,因爲我是能夠改變邊界顏色和圖像尺寸在這裏:

public View getView(int position, View convertView, 
     ViewGroup parent) { 
     ImageView i = new ImageView(mContext); 

     Bitmap bm = BitmapFactory.decodeFile(
     FileList.get(position).toString()); 
     i.setImageBitmap(bm); 
     i.setLayoutParams(new Gallery.LayoutParams(160, 180)); 
     i.setScaleType(ImageView.ScaleType.FIT_XY); 
     i.setBackgroundResource(mGalleryItemBackground); 
     i.setBackgroundColor(Color.BLUE); 
     return i; 
    } 
+0

你可能想檢查一下:http://stackoverflow.com/a/1598200/862629 – 2012-01-27 00:59:58

+0

如果答案在那裏,它就像一根乾草堆裏的針,因爲這實際上是我第一次曾嘗試調整邊界甚至Java或Android中的任何顏色。它是形狀標籤嗎?我不知道。 – Dave 2012-01-27 01:06:41

回答

0

圖像周圍的邊框實際上是背景填充:

i.setPadding(1,1,1,1);

0

你幾乎在那裏。邊框被稱爲中風,你可以像這樣指定它:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:top="1dp" android:left="1dp" 
    android:right="1dp" android:bottom="1dp"> 
    <shape android:shape="rectangle"> 
     <solid android:color="@color/red" /> 
     <stroke android:width="1dp" /> 
    </shape> 
</item> 

+0

看起來,HelloGallery示例在滾動圖像周圍有一個矩形,所以上面發佈的XML可能會引起誤解。這是圖像不是他們周圍的矩形我需要改變。解決方案可能在代碼的完全不同的部分。 – Dave 2012-01-27 01:26:28

相關問題