material-components / material-components/material-components-android
[ShapeableImageView] contentPadding not working when set via Kotlin
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
**Description:**
When setting `contentPadding` on a `ShapeableImageView` in code (Kotlin or Java), it does not work as expected. Setting `app:contentPadding` via `XML` works fine.
**Expected behavior:**
Both elements should match and be like the top element.

**Source code:**
`MainActivity.kt`
```kotlin
package com.example.bug
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.TypedValue
import com.google.android.material.imageview.ShapeableImageView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val px = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
8f,
resources.displayMetrics
).toInt()
findViewById(R.id.kotlin)?.setContentPadding(px, px, px, px)
}
}
```
`activity_main.xml`
```xml
```
`styles.xml`
```xml
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
```
**Android API version:** 30
**Material Library version:** 1.3.0
**Device:** Pixel 3 and others
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the difference between app:contentPadding in activity_main.xml and setContentPadding in MainActivity.kt using ShapeableImageView. Read the ShapeableImageView entry point and styles.xml, then verify that programmatic and XML padding produce the same result on the reported Android setup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java, kotlin
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100