Samuel
Samuel

Reputation: 17

Why aren't my paddings being applied to my image view?

I am trying to position my bookImageTo the left by 15dp but when I add paddings to it nothing happens it remains unchanged. My textviews are responsive to changes when paddings are added to it, but I am not sure why my image view is not. Some help would be greatly appreciated.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark">


    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimaryDark"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/bookImage"
            android:layout_width="170dp"
            android:paddingLeft="@dimen/album_title_padding(this is equal to 15dp)"
            android:paddingTop="@dimen/album_title_padding"
            android:paddingRight="@dimen/album_title_padding"
            android:layout_height="170dp" />


        <TextView
            android:id="@+id/bookTitleTv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/bookImage"
            android:paddingLeft="@dimen/album_title_padding"
            android:paddingTop="@dimen/album_title_padding"
            android:paddingRight="@dimen/album_title_padding"
            android:textColor="#424242"
            android:textSize="@dimen/album_title" />

        <TextView
            android:id="@+id/bookAuthorTv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/bookTitleTv"
            android:paddingLeft="@dimen/album_title_padding"
            android:paddingRight="@dimen/album_title_padding"

            android:paddingBottom="@dimen/songs_count_padding_bottom"
            android:textSize="@dimen/songs_count"
            android:textStyle="italic" />

        <TextView
            android:id="@+id/overflow"
            android:layout_width="@dimen/ic_album_overflow_width"
            android:layout_height="@dimen/ic_album_overflow_height"
            android:layout_below="@+id/bookAuthorTv"
            android:layout_alignBottom="@+id/bookAuthorTv"

            android:layout_alignParentEnd="true"
            android:textSize="15sp"
            android:layout_alignParentRight="true"
            android:layout_marginTop="-29dp"
            android:layout_marginEnd="1dp"
            android:layout_marginRight="1dp"
            android:layout_marginBottom="0dp"
            android:text="@string/vertical_ellipsis"
            android:textColor="@color/colorPrimary" />


    </LinearLayout>


</LinearLayout>

Upvotes: 0

Views: 68

Answers (2)

Jeanne vie
Jeanne vie

Reputation: 524

Based on my understanding about your concern, you only want to put a space on the left specifically for the ImageView only inside the LinearLayout? I tried your code and this is the preview:

BeforeChanging

Use android:layout_marginLeft="15dp" instead of using paddingLeft. After applying this code, preview looks like this:

AfterChanging

Upvotes: 1

Mohit Bansal
Mohit Bansal

Reputation: 398

Try using

android:layout_marginLeft="@dimen/album_title_padding"
android:layout_marginTop="@dimen/album_title_padding"
android:layout_marginRight="@dimen/album_title_padding"

This is discussed here Padding in ImageView is not Working

Instead of wrap_content for both the linear layout. Do match_parent.

enter image description here

Upvotes: 0

Related Questions