每个值都带有布局(imageview + imagebutton)的 Gridview [英] Gridview with layout (imageview + imagebutton) for every value
问题描述
是否可以制作一个网格视图,而不是图片网格,而是图片网格,每个图片下方都有一个小图像按钮?
Is it possible to make a gridview that has instead of a grid of pictures, a grid of pictures with a small imagebutton below every one of them?
推荐答案
简短回答: 是的.您可以在 GridView
中有一个 ImageView
和一个 ImageButton
.
Short answer: Yes. You can have an ImageView
and an ImageButton
in a GridView
.
长答案:
您自然需要为此创建一个自定义的 GridView
.
You will naturally have to create a custom GridView
for that purpose.
例如:
创建一个 XML 来保存容器 GridView
,比如说,grid.xml
:
Create an XML which will hold the container GridView
, say, grid.xml
:
<GridView
android:id="@+id/gridFriends"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clipChildren="true"
android:columnWidth="100dp"
android:fastScrollEnabled="true"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>
并且,为了定义 GridView
的内容,创建另一个 XML 布局,该布局将包含 ImageView
和 ImageButton
.比如说,grid_items.xml
:
And, to define the contents of the GridView
, create another XML layout which will hold the ImageView
and the ImageButton
. Say, grid_items.xml
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<FrameLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="center" >
<ImageView
android:id="@+id/imgProfilePicture"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:src="@null" />
<ImageButton
android:id="@+id/imgbtnDemo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:background="@null"
android:gravity="center"
android:src="@drawable/ic_contact_picture" >
</ImageButton>
</FrameLayout>
</RelativeLayout>
最后,如果您熟悉自定义ListViews
的概念,稍加修改,您也将能够实现自定义GridView
.如果您不熟悉自定义 ListViews
或 GridViews
,请按照本教程查看如何创建自定义 GridView
:http://www.coderzheaven.com/2012/02/29/custom-gridview-in-android-a-simple-example/.或者使用这个 搜索更多相同的教程.
Finally, if you are familiar with the concept of custom ListViews
, with a few modifications, you will be able to implement a custom GridView
too. If you are not familiar with custom ListViews
or GridViews
, follow this tutorial to see how to create a custom GridView
: http://www.coderzheaven.com/2012/02/29/custom-gridview-in-android-a-simple-example/. Or use this Google Search for more tutorials on the same.
这里很重要的一点是,如果你需要 ImageButton's
在被点击时执行一个功能,onClickListener
将需要在适配器
.
An important point here would be, if you need the ImageButton's
to do a function when they are clicked, the onClickListener
will need to be setup in the Adapter
.
这篇关于每个值都带有布局(imageview + imagebutton)的 Gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!