我在gridview中显示图像和文本.即每个项目由一个图像和一个文本组成.它工作正常.但我想知道如何在 android中分别设置每个gridview项的边框. 1)在res value文件夹下创建一个attrs.xml. 2)添加资
2)添加资源:
<declare-styleable name="Gallery1"> <attr name="android:galleryItemBackground" /> </declare-styleable>
3)在您的相应活动中添加以下代码:
TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); int mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle();
4)然后将mGalleryItemBackground设置为视图的背景.您将在视图之外获得边框.
例如:
imageView.setBackgroundResource(mGalleryItemBackground);