<ImageView 
  android:layout_below="@+id/LinearLayout05" 
  android:layout_alignLeft="@+id/LinearLayout05" 
  android:id="@+id/ImageView01" 
  android:src="#FFFF0000" 
  android:layout_height="80dp" 
  android:layout_width="60dp"
  android:background="@android:drawable/btn_default" 
  android:paddingBottom="20dp" 
  android:paddingLeft="120dp" 
  android:paddingRight="20dp" 
  android:paddingTop="20dp" 
  android:scaleType="fitCenter">
</ImageView>
我这样设置后,整个ImageView都是红色的,背景完全被盖住了。该如何给ImageView加边框啊?

解决方案 »

  1.   

    在ImageView的上下左右都加个View就行了,
    view控制好view的高宽顡色就好了
      

  2.   

    要么自己定义一个view,要么就用一个带边框图片也挺好的呀。
      

  3.   

    三个方法:1. android:src= "#FFFF0000 " 中前面2个改为 "#33FF0000" 设置一定的透明度,这样红色就不会盖住background了。2. android:src= "@android:drawable/btn_default" 
       android:background= "#FFFF0000"
       android:scaleType= "fitCenter"   这边需要注意的是src中的drawable的长宽需要比ImageView长宽至少各小4px。3. 继承ImageView实现它的onDraw函数。个人倾向于使用第三种方法。
      

  4.   

    直接用android SDK自带的draw9patch工具做一个中间是空白的有边框的xxx.9.png图片用作ImageView的背景就可以了。
      

  5.   

    既然已经设置了background,那去掉android:src= "#FFFF0000 " 不就行了么
      

  6.   

    Gallery控件中可以添加边框,当时写过一点,楼主可以仿照这个处理一下试试:ApiDemo中有一个例子:1、声明item背景变量   int mGalleryItemBackground;
    2、在适配器的构造函数中写如下代码:
    public ImageAdapter(Context c) {
                mContext = c;
                // See res/values/attrs.xml for the <declare-styleable> that defines
                // Gallery1.(此注释说明了该自定义风格的位置,在res/values/attrs.xml中)
                TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
        /*此处obtainStyledAttributes方法如果报错,The method obtainStyledAttributes(int[]) is undefined for the type ImageAdapter,做如下修改*/
        //TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);     
                mGalleryItemBackground = a.getResourceId(
                        R.styleable.Gallery1_android_galleryItemBackground, 0);
                a.recycle();
            }
    3、在getView方法中添加一行代码即可:
    imageView.setBackgroundResource(mGalleryItemBackground);如此便为Gallery每个item添加了边框。
      

  7.   

    用不着那么麻烦,ImageView设置个Margin属性就可以;然后放入你想放入的View中即可。<LinearLayout android:orientation="vertical"
     android:layout_width="wrap_content" android:layout_height="wrap_content"
     android:background="@drawable/color_orange" android:gravity="center">
     <ImageView android:id="@+id/chanshow_img_icon"
      android:layout_width="50dp" android:layout_height="50dp"
      android:layout_margin="2dp" />
    </LinearLayout>
      

  8.   


    这个方法,简单,实用,很好,还有一种方法也是这样的。
    定义一个<?xml version="1.0" encoding="UTF-8"?>
    <shape
      xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#000000" />
        <stroke android:width="3.0dip" android:color="#000000" />
        <corners android:radius="2.0dip" />
        <padding android:left="0.0dip" android:top="0.0dip" 
        android:right="0.0dip" android:bottom="0.0dip" />
    </shape> <ImageView
    android:id="@+id/allimageview"
    android:layout_width="114px"
    android:layout_height="80px"

    android:layout_margin="8dip"
    android:layout_alignParentLeft="true"
    android:background="@drawable/sms_type_bg"
    />