android를 사용하여 RadioGroup에 이미지를 붙여넣고 사용자 정의하는 방법
울면서 했어요.
다음은 완성례입니다.
(왼쪽부터 작은 칼, 포크, 숟가락의 자유로운 소재를 사용했습니다. 너무 길지만 그럭저럭 그림만 붙였습니다. 용서해 주십시오)

iOS 개발에서 말한 UISegment와 같습니다.
그림을 붙여서 사용자 정의하는 방법이 전혀 없기 때문이다.
그럼 바로
1. Radio Group을 UISegment에 배치하기
fragment_main.xml
<RadioGroup
android:id="@+id/uisegment"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginHorizontal="40dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:checkedButton="@+id/left"
android:orientation="horizontal">
<RadioButton
android:id="@+id/left"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@drawable/segmented_left"
android:button="@null"
android:layout_weight="1" />
<RadioButton
android:id="@+id/center"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@drawable/segmented_center"
android:button="@null"
android:layout_weight="1"/>
<RadioButton
android:id="@+id/right"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@drawable/segmented_right"
android:button="@null"
android:layout_weight="1"/>
</RadioGroup>
RadioButton에서 이미지 섹션 설정하기android:background="@drawable/segmented_left"
여기서 해.
나는 여기에 직접 소재를 설정하지 않는 것이 매우 중요하다고 생각한다.(일반)
(drawable의
segmented_left
segmented_center
segmented_right
이것에 관해서는 내가 다음에 할게.보시다시피segment의 왼쪽, 중간, 오른쪽과 장미 장미.
그 밖에
android:button="@null "
여기서 기본 단추 삭제
2. 왼쪽 단락 만들기
2.1 세션을 선택했을 때(클릭되었을 때)와 클릭하지 않았을 때 그림을 분리해서 출력합니다
(색상 변경이 필요하기 때문에)
segmented_left.xml
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 選択時 -->
<item android:drawable="@drawable/segmented_left_checked" android:state_checked="true"/>
<!-- 非選択時 -->
<item android:drawable="@drawable/segmented_left_normal"/>
</selector>
그다음에 할 건요.segmentedd_left_normal 및segmentedd_left_checked야.
2.2 선택한 세그먼트의 이미지 만들기
segmented_left_checked.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- ベタ塗り -->
<item>
<shape android:shape="rectangle" >
<corners
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp" />
<solid android:color="@color/segmented_color" />
</shape>
</item>
<item
android:state_checked="true"
android:top="10dp"
android:bottom="10dp"
android:left="15dp"
android:right="15dp"
android:width="60dp"
android:height="15dp"
android:gravity="center">
<bitmap
android:src="@drawable/nife"
android:tint="#ffffff" />
</item>
<!-- ボーダー -->
<item>
<shape android:shape="rectangle" >
<corners
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp" />
<stroke
android:width="0.5dp"
android:color="@color/segmented_around_color" />
</shape>
</item>
</layer-list>
layer-list를 사용하여 세 개의 item을 중첩합니다.첫 번째 항목은 단락의 기초이다.
두 번째 항목에서 처음으로 원래의 그림을 당겼다.
비트맵에서
android:tint='fffff'와 원본 이미지의 배경색은 매혹적인 곳입니다.
배경의 색상을 전혀 지정할 수 없습니다.
2.3 선택되지 않은 세그먼트 만들기
단지 위의 코드와 색깔의 지정은 다르지만, 당분간 선택하지 않은 xml도 미리 게재됩니다.
segmented_left_normal.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- ベタ塗り -->
<item>
<shape android:shape="rectangle" >
<corners
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp" />
<solid android:color="#ffffff" />
</shape>
</item>
<item
android:state_checked="true"
android:top="10dp"
android:bottom="10dp"
android:left="15dp"
android:right="15dp"
android:width="60dp"
android:height="15dp"
android:gravity="center">
<bitmap
android:src="@drawable/nife"
android:tint="@color/segmented_color" />
</item>
<!-- ボーダー -->
<item>
<shape android:shape="rectangle" >
<corners
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp" />
<stroke
android:width="0.5dp"
android:color="@color/segmented_around_color" />
</shape>
</item>
</layer-list>
segmented_center, segmented_right도 같은 요령으로 만들 수 있습니다.다만 UISegment를 맞춤형으로 만들어야 하기 때문에 9개의 xml을 만들어야 한다는 게 무서워요.
Reference
이 문제에 관하여(android를 사용하여 RadioGroup에 이미지를 붙여넣고 사용자 정의하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/marienplatz/items/eab522fb8bd9fe7200f3텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)