Dev_Cob
Dev_Cob

Reputation: 101

In Android how can we add a checkbox with a text and a icon?

Please help me to understand how we can design the following view?

view- icon with text and checkbox In reality this would be a part of a grid view.

I could add a text view and a image view to have the icon and text together with the following layout design. But I am not sure how I can add a check box with it.

`
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    your text`xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/grid_item"
        android:orientation="vertical"
        android:layout_width="@dimen/width"
        android:layout_height="@dimen/height"
        android:layout_marginBottom="@dimen/margin_bottom">

        <ImageView
            android:id="@+id/image"
            android:layout_width="@dimen/img_width"
            android:layout_height="@dimen/img_height"
            android:layout_gravity="center"
            android:background="@drawable/selector"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintTop_toBottomOf="parent"
            android:layout_marginTop="@dimen/margin_top"
            android:layout_marginStart="@dimen/margin_start"
            android:layout_marginEnd="@dimen/margin_end"
            />

        <TextView
            style="@style/text_type_t24"
            android:id="@+id/grid_item_label"
            android:layout_width="@dimen/label_width"
            android:layout_height="@dimen/label_height"
            android:layout_marginTop="@dimen/label_margin_top"
            android:textColor="@color/white"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/image">
        </TextView>
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>
`

Upvotes: 0

Views: 55

Answers (1)

Kishan Maurya
Kishan Maurya

Reputation: 3394

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/grid_item"
        android:layout_width="@dimen/width"
        android:layout_height="@dimen/height"
        android:layout_marginBottom="@dimen/margin_bottom">

        <androidx.appcompat.widget.AppCompatCheckBox
            android:id="@+id/checkbox"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:checked="false"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/image"
            android:layout_width="@dimen/img_width"
            android:layout_height="@dimen/img_height"
            android:layout_gravity="center"
            android:src="@mipmap/ic_launcher"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/checkbox" />

        <TextView
            android:id="@+id/grid_item_label"
            style="@style/text_type_t24"
            android:layout_width="@dimen/label_width"
            android:layout_height="@dimen/label_height"
            android:layout_marginTop="8dp"
            android:text="Settings"
            android:textColor="@color/black"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/image" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</layout>

Upvotes: 0

Related Questions