Search code examples
androidlayoutpadding

Left and top padding for CheckBox doesn't work


I want to create layout for Custom Adapter. It should be line with checkbox, icon and textView.

I use next layout xml configuration for row:

<LinearLayout
        android:id="@+id/list_item_row"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <CheckBox
            android:id="@+id/checkboxFileSelect"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:button="@drawable/checkbox_icon"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:checked="false"
            android:visibility="visible"/>

        <ImageView
            android:id="@+id/folder_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/folder_icon"
            android:layout_gravity="center_vertical"/>

        <TextView
            android:id="@+id/current_folder"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textColor="@color/primaryText"/>

    </LinearLayout>

but left and top padding doesn't work. When I add left and right padding it only increase right padding value.

example image here

enter image description here


Solution

  • You have to use android:layout_marginLeft for this usecase.

    Padding is the space inside the component. e.g: space between the text and the border of TextView.

    Margin is the space outside the components. e.g: space between left edge of the screen and border of your component