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