fragment_camera.xml:的Android按鈕背景形狀:圓壓扁
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
android:id="@+id/iv_camera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" >
</ImageView>
<Button
android:id="@+id/btn_take_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:background="@drawable/circle" >
</Button>
</RelativeLayout>
circle.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#87cefa"/>
<size
android:width="40dp"
android:height="40dp"/>
</shape>
結果:
我圓壓扁*哭*。
由於按鈕不包含任何內容我猜這個按鈕有一個默認的寬度和高度。我怎樣才能讓按鈕調整到drawable?我是否必須將寬度和高度設置爲與drawable相同的尺寸,還是有動態的方式來做到這一點?
不,你不能。唯一的方法是定義按鈕的尺寸。背景可繪製總是被強制爲視圖的尺寸。 –
@iRaviiVooda好吧,這就是我害怕的,猜想我必須咬緊牙關。 –