开发者

Android:Adding a checkbox to the images in gridview

I have images displayed in gridView and now i need to add a checkbox to each image , so as to allow multiple selection.

Q: How to ad开发者_开发技巧d checkbox to the image in grid view in android ? (e.g. Gallery Application has the same functionality)


You can use FrameLayout for it.

<FrameLayout
        android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="9dip"
    android:padding="5dip">

    <ImageView
        android:id="@+id/image1"        
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dip"
        android:layout_gravity="right|center_vertical"
            android:background="@drawable/delete"/>
             <CheckBox
        android:id="@+id/chk_box"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

</FrameLayout>


You can create simple CheckBox(http://developer.android.com/reference/android/widget/CheckBox.html) and use setCompoundDrawables to add icon to it. Than just add this component to your grid.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜