Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkbox in imageview

Tags:

android

I am having a requirement to have checkbox in imageview,how to design the layout.xml file for that,on click of the imageview the checkbox sholud be checked. I can handle the job of checking the checkbox when clicked on imageview. Can any one solve my problem to design simple layout of checkbox should lie in ImageView.

like image 694
user2285035 Avatar asked Sep 05 '26 23:09

user2285035


1 Answers

Here is your answer use it in custom adapter class

 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ImageView
            android:id="@+id/img"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_launcher" />

        <CheckBox
            android:id="@+id/chkBox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/txtPersonName"
            android:layout_alignRight="@+id/txtPersonName" />

        </RelativeLayout>

Updated xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/txtPersonName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_launcher" />

    <CheckBox
        android:id="@+id/chkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignRight="@+id/txtPersonName" />

    </RelativeLayout>
like image 78
Hanish Sharma Avatar answered Sep 07 '26 14:09

Hanish Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!