0
我在寫一個應用程序,我需要在相同的水平空間中繪製兩個單選按鈕。我通過設置android:layout_weight =「1」這兩個單選按鈕來實現屬性。顯示自定義繪圖和單選按鈕中心的文本
現在我需要在中心顯示自定義繪製按鈕,需要放置文本繪製的裏面,是這樣的:兩個
以下行爲畫繪製和文字是動態的。
有什麼辦法可以在中心實現這兩件事。
我在寫一個應用程序,我需要在相同的水平空間中繪製兩個單選按鈕。我通過設置android:layout_weight =「1」這兩個單選按鈕來實現屬性。顯示自定義繪圖和單選按鈕中心的文本
現在我需要在中心顯示自定義繪製按鈕,需要放置文本繪製的裏面,是這樣的:兩個
以下行爲畫繪製和文字是動態的。
有什麼辦法可以在中心實現這兩件事。
試試下面的代碼來實現所需的輸出。
<?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:orientation="horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/rd_bg"
android:button="@null"
android:gravity="center"
android:text="15"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<RadioButton
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@null"
android:background="@drawable/rd_bg"
android:gravity="center"
android:text="30"/>
</LinearLayout>
</LinearLayout>
下面是繪製duration_selector
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:state_focused="true">
<shape android:shape="oval">
<solid android:color="@color/login_bg"/>
<size
android:width="50dp"
android:height="50dp"/>
</shape>
</item>
<item
android:state_checked="false"
android:state_focused="true">
<shape android:shape="oval">
<solid android:color="@color/login_bg"/>
<size
android:width="50dp"
android:height="50dp"/>
</shape>
</item>
<item
android:state_checked="true">
<shape android:shape="oval">
<solid android:color="@color/login_bg"/>
<size
android:width="50dp"
android:height="50dp"/>
</shape>
</item>
<item
android:state_checked="false">
<shape android:shape="oval">
<solid android:color="@android:color/transparent"/>
<stroke android:color="@color/login_bg"
android:width="1dp"/>
<size
android:width="50dp"
android:height="50dp"/>
</shape>
</item>
@顏色代碼/ login_bg是顏色代碼,你想使用。
嗨..感謝您的回答。但是因爲我需要將按鈕放在相同的水平空間中。因此,然後bg圖像「duration_selector」得到拉伸和文本在左邊對齊。任何其他建議! – CoDe 2014-11-03 08:42:03
@Shubh您可以查看解決方案http://stackoverflow.com/a/19163987/1839336。它可能會幫助你 – GrIsHu 2014-11-03 08:59:43
@ Shubh請檢查已編輯的答案 – miteshpithadiya 2014-11-03 09:02:59