<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加边框啊?
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加边框啊?
解决方案 »
- 如何在自己的app中实现关机和重启?
- 请教类似“我查查”软件的支持无自动对焦手机的条码识别,是如何实现的?
- ListView焦点问题
- Android2.2源码下的/frameworks/base/media/java/android/drm/mobile1下的java类在Activi中不能用?
- webkit怎么能够解析出wml页面?
- 有懂android的兄弟姐妹伐?有项目合作,待遇优厚
- Android基础之Activity launchMode
- Log.i(TAG,"item clicked");
- 关于自定义alterDialog的问题
- android studio虚拟机运行不出来怎么办
- 有没人知道如何通过gsm/gprs获得地理位置啊?
- AutoCompleteTextView 显示所有的数据
view控制好view的高宽顡色就好了
android:background= "#FFFF0000"
android:scaleType= "fitCenter" 这边需要注意的是src中的drawable的长宽需要比ImageView长宽至少各小4px。3. 继承ImageView实现它的onDraw函数。个人倾向于使用第三种方法。
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添加了边框。
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>
这个方法,简单,实用,很好,还有一种方法也是这样的。
定义一个<?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"
/>