2

線形レイアウト (水平) に含まれる 3 つのボタン コントロールを含む画面レイアウトがあります。ボタンにはそれぞれ背景画像があります。以下の XML を参照してください。

<LinearLayout
    android:id="@+id/notificationform_llt_ApprovalBtns"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="8dp"
    android:orientation="horizontal"
    android:paddingLeft="8dp"
    android:paddingRight="8dp" >

    <Button
        android:id="@+id/notificationform_btn_Approve"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@drawable/btn_approve"
        android:onClick="btnApprove_Click" />
    <Button
        android:id="@+id/notificationform_btn_Reject"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@drawable/btn_reject"
        android:onClick="btnReject_Click" />
    <Button
        android:id="@+id/notificationform_btn_Delegate"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:background="@drawable/btn_delegate"
        android:onClick="btnDelegate_Click" />
</LinearLayout>

画面は私の Galaxy W 携帯電話 (3.7 インチ) では見栄えがしますが、Nexus 7 で実行すると、ボタンは水平方向に伸びますが垂直方向には伸びないため、押しつぶされたように見えます。正しく理解すれば、これらのデバイスはどちらも解像度が似ていて、どちらも画像を探します。画像が保存されている drawable-hdpi フォルダーに. 画像を 9-patch にしてみましたが、違いはありませんでした. 画像を高さと幅の両方に比例してスケーリングするにはどうすればよいですか?

4

1 に答える 1

6

LinearLayoutが に設定されているため、ボタンは水平方向に引き伸ばされます。fill parent各ボタンには、引き伸ばされるbuttonウェイトがあります。高さは に設定されてwrap_contentおり、コンテンツはありません。画像は背景として設定されており、画像の大きさには影響しませんbutton

Buttons を ImageButtons に変更し、android:src代わりに使用することをお勧めしますandroid:background。例えば ​​:

<ImageButton
    android:id="@+id/notificationform_btn_Approve"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:src="@drawable/btn_approve"
    android:onClick="btnApprove_Click" />
于 2012-10-03T16:46:28.713 に答える