与GridView的布局(ImageView的+的ImageButton)为每个价值 [英] Gridview with layout (imageview + imagebutton) for every value
问题描述
时有可能使拥有的图片,而不是一格的GridView,图片与他们每个人?
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?
推荐答案
的简短的回答:的是。您可以在的ImageView
和的ImageButton
A GridView控件
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>
最后,如果你熟悉定制的概念列表视图
,有一些修改,您就可以实现自定义的 GridView控件
太。如果你不熟悉的自定义列表视图
或 GridView的
,请按照本教程来看看如何创建自定义的 GridView控件
:<一href=\"http://www.$c$crzheaven.com/2012/02/29/custom-gridview-in-android-a-simple-example/\">http://www.$c$crzheaven.com/2012/02/29/custom-gridview-in-android-a-simple-example/.或使用本<一个href=\"https://www.google.co.in/#hl=en&safe=off&tbo=d&sclient=psy-ab&q=android+custom+gridview+example&oq=android+custom+gridview&gs_l=hp.3.1.0j0i7j0l2.67.6157.0.7796.23.23.0.0.0.6.474.4796.0j14j5j2j2.23.0.les%3B..0.0...1c.1.2.hp.mQ3YMh3tzDI&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&bvm=bv.42080656,d.bmk&fp=aa8f2157e742c828&biw=1440&bih=775\">Google搜索对同一更多的教程。
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的
做了一个功能被点击时,在 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
.
这篇关于与GridView的布局(ImageView的+的ImageButton)为每个价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!