How to change border thickness around images in HelloGallery

时间秒杀一切 提交于 2019-12-11 14:38:36

问题


I'm not really sure if it's the thickness of the border or the margin around the image that needs to be changed. I have never worked with styles before, and just created a styles.xml and colors.xml file for the first time. I have changed the background color to Red, using the code below in image_border.xml. But I do not know how to change the border thickness around the images in HelloGallery.

Perhaps it's not in this file. But what exactly needs to be written in the code?

<?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>

Edit: The answer might actually be a matter of modifying this portion of the code, since I was able to change the border color and image size here:

    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;
    }

回答1:


You're almost there. A border is called a stroke, you can specify it like this:

<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>




回答2:


I think a simple solution for you is here:

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

hope it helps




回答3:


The border around the image actually is background padding:

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



来源:https://stackoverflow.com/questions/9027663/how-to-change-border-thickness-around-images-in-hellogallery

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!