android source

imageview with rounded corner

리오파파 2023. 12. 19. 22:31

1. implementation is required

implementation 'com.google.android.material:material:1.6.0'

 

2. define custom tyle xml

아래는 rounded corner 외에 여러가지 경우가 있음

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Circular">
<item name="cornerSize">50%</item>
</style>

<style name="RoundedSquare">
<item name="cornerSize">10%</item>
</style>

<style name="CornerCut">
<item name="cornerSize">15dp</item>
<item name="cornerFamily">cut</item>
</style>

<style name="DiamondCut">
<item name="cornerSize">75dp</item>
<item name="cornerFamily">cut</item>
</style>

<style name="SpecificCornerCut">
<item name="cornerSizeTopRight">75dp</item>
<item name="cornerFamilyTopRight">cut</item>
<item name="cornerSizeBottomLeft">75dp</item>
<item name="cornerFamilyBottomLeft">cut</item>
</style>

<style name="SpecificCornerRounded">
<item name="cornerSizeTopRight">75dp</item>
<item name="cornerFamilyTopRight">rounded</item>
<item name="cornerSizeBottomLeft">75dp</item>
<item name="cornerFamilyBottomLeft">rounded</item>
</style>

</resources>

 

3. layout에 imageview 대신 imageview.ShapeableImageView 를 적용

이 xml에서 shapeAppearanceOverlay 가 key 임


<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="@id/info"
android:layout_centerHorizontal="true"
android:layout_marginStart="3dp"
android:layout_marginTop="3dp"
android:layout_marginEnd="3dp"
android:layout_marginBottom="3dp"
android:padding="3dp"
android:scaleType="fitXY"
app:layout_constraintHorizontal_bias="0.5"
app:shapeAppearanceOverlay="@style/RoundedSquare" />

 

'android source ' 카테고리의 다른 글

text prompted box input  (0) 2024.03.28
toolbar menu width adjust  (0) 2024.03.03
Google File Async Download  (0) 2023.12.17
drawable resource를 bitmap으로  (1) 2023.12.17
phone vibrate  (0) 2023.12.17