我想在同一行中獲得3個具有相同大小的ImageButton。ImageButton Scale
我想要的東西,這就像:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/black"
android:orientation="vertical"
android:paddingBottom="40dp"
android:paddingTop="40dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|fill_horizontal|center"
android:gravity="fill_horizontal" >
<LinearLayout
android:id="@+id/dummy_005"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
</LinearLayout>
<ImageButton
android:id="@+id/button_scan"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="@drawable/image_button"
android:focusableInTouchMode="true"
android:scaleType="fitCenter"
android:
android:src="@drawable/scan_symbol" />
<LinearLayout
android:id="@+id/dummy_002"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
</LinearLayout>
<ImageButton
android:id="@+id/button_hitsorie"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="@drawable/image_button"
android:src="@drawable/historie_symbol" />
<LinearLayout
android:id="@+id/dummy_003"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
</LinearLayout>
<ImageButton
android:id="@+id/button_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="@drawable/image_button" />
<LinearLayout
android:id="@+id/dummy_004"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="@dimen/testTextSize" />
</LinearLayout>
</LinearLayout>
的問題:我希望該按鈕會quadtra(寬度==高度)。但寬度爲「0dp」,重量爲3.但我怎麼能按鈕高度縮放?
謝謝
繼承ImageButton類的子類,並在計算寬度後將高度設置爲等於寬度。然後使用您的自定義ImageButton類而不是股票。 – peshkira 2014-09-02 11:29:20
@peshkira有正確的想法..請參閱我的工作示例代碼的答案。 – speedynomads 2014-09-02 12:09:26