如何在HelloGallery中更改图像周围的边框厚度

时间:2012-01-27 00:51:47

标签: android

我不确定是否需要更改边框的粗细或图像周围的边距。我之前从未使用过样式,并且第一次创建了styles.xml和colors.xml文件。我已使用image_border.xml中的以下代码将背景颜色更改为红色。但我不知道如何更改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;
    }

3 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

我认为一个简单的解决方案就在这里:

http://groups.google.com/group/android-developers/browse_thread/thread/157740b639959c47?pli=1

希望有所帮助

答案 2 :(得分:0)

图像周围的边框实际上是背景填充:

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

相关问题