티스토리 뷰
Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.
Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.
아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

Border for an Image view in Android?
안드로이드에서 ImageView에 테두리 설정
문제 내용
How can I set a border for an ImageView
and change its color in Android?
안드로이드에서 ImageView에 테두리를 설정하고 색상을 변경하는 방법은 무엇인가요?
높은 점수를 받은 Solution
I set the below xml to the background of the Image View as Drawable. It works.
아래의 xml을 Image View의 Drawable로서 배경으로 설정합니다. 이렇게 하면 작동합니다.
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<stroke android:width="1dp" android:color="#000000" />
<padding android:left="1dp" android:top="1dp" android:right="1dp"
android:bottom="1dp" />
</shape>
And then add android:background="@drawable/yourXmlFileName"
to your ImageView
그리고 ImageView에 android:background="@drawable/yourXmlFileName"을 추가합니다.
가장 최근 달린 Solution
With Material design and the new ShapeableImageView widget, you can easily create an image that has a border using the strokeColor
and strokeWidth
attributes. This is simple and doesn't involve creating any extra XML file.
Material design과 새로운 ShapeableImageView 위젯을 사용하면, strokeColor 및 strokeWidth 속성을 사용하여 테두리가 있는 이미지를 쉽게 만들 수 있습니다. 이것은 간단하며 추가 XML 파일을 생성하는 것이 필요하지 않습니다.
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="200dp"
android:layout_height="200dp"
app:strokeColor="@color/black"
app:strokeWidth="2dp"
app:srcCompat="@drawable/sample_image" />
The above code creates a black border with a width of 2dp.
위의 코드는 너비가 2dp이며 검은색 테두리를 만듭니다.
In cases where you might want to add a stroke to rounded image, you can use the shapeAppearanceOverlay
attribute. This allows you to draw the bitmap with the provided shape (round in this case). Check the below code for more details:
둥근 이미지에 스트로크를 추가하려는 경우 shapeAppearanceOverlay 속성을 사용할 수 있습니다. 이것은 제공된 모양(이 경우 둥근 모양)으로 비트맵을 그리도록 합니다. 자세한 내용은 아래 코드를 확인하세요.
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="200dp"
android:layout_height="200dp"
app:shapeAppearanceOverlay="@style/circleImageView"
app:srcCompat="@drawable/sample_image"
app:strokeColor="@color/black"
app:strokeWidth="2dp" />
Add the below code to your styles.xml
file:
다음 코드를 styles.xml 파일에 추가합니다.
<!-- Circle Shape -->
<style name="circleImageView" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSize">50%</item>
</style>
Make sure your app extends the material design theme in order to use the ShapeableImageView
.
ShapeableImageView를 사용하려면 앱이 Material Design 테마를 확장해야합니다.
출처 : https://stackoverflow.com/questions/3263611/border-for-an-image-view-in-android
'개발 > 안드로이드' 카테고리의 다른 글
모바일 웹사이트 입력창에 포커스가 갈 때 숫자 키패드가 나오게 하기 (0) | 2023.02.10 |
---|---|
매개변수와 함께 액티비티 시작하기 (0) | 2023.02.10 |
merge tag를 사용한 레이아웃 안드로이드 스튜디오에서 미리보기 (0) | 2023.02.10 |
액티비티 없는 객체에서 리소스 컨텐츠 가져오기 (0) | 2023.02.10 |
안드로이드에서 애니메이션 없이 액티비티 전환하기 (0) | 2023.02.09 |