2012-01-25 25 views
11

Tôi đang cố tạo danh sách nút radio gồm 4 mục. Mỗi mục cần phải có văn bản cho nó đúng, nhưng cũng là một hình ảnh ở bên phải của văn bản. Hình ảnh không phải là nút radio, đó là một hình ảnh mô tả tùy chọn. Tôi không có may mắn cho đến nay, nhà thiết kế dường như vô dụng để đưa mọi thứ vào đúng chỗ. Bạn phải biết cách viết mã này trong XML. XML của tôi trông như thế này:Cách đặt hình ảnh ở bên phải của nút radio, Android

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" android:weightSum="1" android:baselineAligned="true" android:orientation="horizontal"> 
    <RadioGroup android:layout_weight="0.50" android:layout_height="wrap_content" android:id="@+id/radioGroup1" android:layout_width="0dp"> 
     <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:checked="true" android:text="A" android:id="@+id/radio0"></RadioButton> 
     <ImageView android:layout_toRightOf="@id/radio0" android:layout_height="wrap_content" android:src="@drawable/A2" android:layout_width="wrap_content" android:id="@+id/imageView1"></ImageView> 
     <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="B" android:id="@+id/radio1"></RadioButton> 
     <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="C" android:id="@+id/radio2"></RadioButton> 
     <RadioButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="D" android:id="@+id/radio3"></RadioButton> 
    </RadioGroup> 

</LinearLayout> 

Ở đây tôi tryiong để đưa một hình ảnh ở bên phải của nút radio đầu tiên, không có thành công. Làm cách nào để đặt hình ảnh ở bên phải của các nút radio?

Trả lời

17

Đối với một nút, bạn có thể đặt drawables vào trên cùng/phải/trái/dưới của nó. Vì vậy, tôi nghĩ rằng nó có thể làm việc theo cùng một cách cho radiobutton.

Có một cái nhìn tại this link trong các nhà phát triển trang web android

Bạn đã thử này?

Cập nhật

Vì vậy, trong trường hợp của bạn, loại bỏ các ImageView và thêm android:drawableRight (hoặc trái/dưới/trên cùng) trong radiobuttons bạn

<RadioButton 
    android:drawableRight="@drawable/A2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:checked="true" 
    android:text="A" 
    android:id="@+id/radio0"/> 
0

Sử dụng android:drawableXXXXX theo quan điểm của bạn để thêm images/drawable , sử dụng padding drawable nếu bạn muốn thêm một số padding.

1
<RadioButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:drawableLeft="@drawable/ic_launcher"/> 

RadioButton chính nó chứa TextView làm mặc định .. để bạn có thể thực hiện tất cả các thao tác có sẵn cho bất kỳ TextView nào.

THƯỞNG: Nếu bạn muốn thay đổi dấu chấm tròn hiển thị trạng thái kiểm tra, chỉ cần cập nhật thẻ android: button để tham chiếu đến hình vẽ của riêng bạn.

Các vấn đề liên quan