4

問題: ImageButtons を適切な場所に表示したり、適切なサイズにしたりすることができないようです。

プラットフォーム: Android API 16 を使用した Eclipse

問題: 私の RelativeLayout は 600x800 で、ImageButtons は 194x64 ですが、エディターに配置すると、本来の 2 倍の大きさになります。画像へのリンクを参照してください。

ここに画像の説明を入力

私のXML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/main_portal_bg" >

    <RelativeLayout
        android1:layout_width="353dp"
        android1:layout_height="758dp"
        android1:layout_marginLeft="115dp"
        android1:layout_marginTop="29dp"
        android1:background="#000000" >
    </RelativeLayout>

    <ImageButton
        android1:id="@+id/new_customer_button_selector"
        android1:layout_width="194dp"
        android1:layout_height="64dp"
        android1:layout_marginTop="89dp"
        android1:contentDescription="@string/back_button_desc"
        android1:background="@drawable/new_customer_button_selector" />

    <ImageButton
        android1:id="@+id/returning_customer_button_selector"
        android1:layout_width="194dp"
        android1:layout_height="64dp"
        android1:layout_alignParentLeft="true"
        android1:layout_below="@+id/new_customer_button_selector"
        android1:contentDescription="@string/back_button_desc"
        android1:src="@drawable/returning_customer_button_selector" />

    <ImageButton
        android1:id="@+id/redeem_coupon_button_selector"
        android1:layout_width="194dp"
        android1:layout_height="64dp"
        android1:layout_alignParentLeft="true"
        android1:layout_below="@+id/returning_customer_button_selector"
        android1:contentDescription="@string/back_button_desc"
        android1:src="@drawable/redeem_coupon_button_selector" />

    <ImageButton
        android1:id="@+id/info_button_selector"
        android1:layout_width="194dp"
        android1:layout_height="64dp"
        android1:layout_alignParentLeft="true"
        android1:layout_below="@+id/redeem_coupon_button_selector"
        android1:contentDescription="@string/back_button_desc"
        android1:src="@drawable/info_button_selector" />

</RelativeLayout>

調査: FitXY の ScaleType を使用し、MaxHeight と MinHeight を設定し、android:src の代わりに android:background を使用しようとしました。小さくすることができた唯一の方法は、グラフィカル エディターを使用して、Shift キーを押しながら右下隅をドラッグしてサイズを変更することです。残念なことに、それらは自動的にレイアウトの下部に配置され、移動しようとすると元のサイズに戻り、他のすべてのボタンがレイアウトの周りでシャッフルされます。XML を編集しても、その方法の一部しか得られません。

質問: グラフィカル エディターでボタンを移動しようとするたびに、他のすべてのボタンが画面上で一見ランダムなパターンでシャッフルされます。なぜこれが起こるのですか?

幅 194 dp、高さ 64 dp に設定しました。これらの値を変更しても何も起こりません。これが ImageButton の実際の幅と高さに影響しないのはなぜですか?

グラフィカル エディターを使用して Shift キーを押しながら角をドラッグしてボタンのサイズを変更すると、XML の幅と高さの値は変更されず、余白が追加されるだけです。以下の結果の XML を参照してください。

   <ImageButton
        android1:id="@+id/new_customer_button_selector"
        android1:layout_width="194dp"
        android1:layout_height="64dp"
        android1:layout_alignParentBottom="true"
        android1:layout_alignRight="@+id/returning_customer_button_selector"
        android1:layout_marginBottom="408dp"
        android1:layout_marginRight="86dp"
        android1:layout_marginTop="89dp"
        android1:background="@drawable/new_customer_button_selector"
        android1:contentDescription="@string/back_button_desc" />

これが私の最終目標です:

ここに画像の説明を入力

どうすればそこに行けるか教えてください。この単純なことはもっと簡単なはずです。

4

1 に答える 1

0

developer.android.com/guide/practices/screens_support.html で提供されている情報を読んだ後、4 種類の画面密度について理解できました。そのリンクのCaseyBに感謝します。

http://members.ping.de/~sven/dpi.htmlで見つけたユーティリティを使用した後、画面密度を約 160 と計算しました。

私の問題は、AVD Manager によって作成されたデフォルトの AVD の LCD 密度が 240 (高) に設定されていることでした。

160 に設定した後、私のプロジェクトはボタンで正しいサイズでレンダリングされました。

私は 1 画面解像度と密度で開発しているので、すべてのドローアブルを drawables フォルダーに残しました。別のタブレットを使用することにした場合は、他のフォルダーを利用する可能性があります。

ヒント:アセットの配置やサイズ変更を Eclipse グラフィカル エディターに依存しないでください。完全に正確かどうかはわかりません。サイズと間隔を調整しようとするときは、XML を編集してプロジェクト メソッドを実行する古い方法を使用します。

于 2012-10-14T14:20:39.437 に答える