-1

さて、この問題は約2週間私を悩ませてきました、そして私が行ったすべての研究で、私はまだこれを理解することができません。円グラフの形で6つのボタンがあります。XMLでレイアウトを行うと、見栄えを良くすることができます。

達成したいビュー

タブレットサイズまたは別のサイズの画面に変更すると、すべてのボタンが動き、ひどく見えます。

悪い眺め

これらのボタンを任意の画面サイズで静止させるにはどうすればよいですか?適切なフォルダに異なる画像サイズを設定する必要があることはわかっています。これを実行する予定ですが、XMLファイルの特定の位置にこれらをロックする方法があるかどうか、または何をする必要があるかを知る必要があります。これを正しく機能させます。いつものように、すべての助けは大歓迎です、そして、私が私の質問について十分に明確でないならば、私はどんな質問にも答えます。ありがとう

これが私のXMLです

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

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="25dp"
    android:background="@drawable/ipadcollegesm" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/button1"
    android:layout_alignRight="@+id/button1"
    android:layout_marginBottom="92dp"
    android:background="@drawable/ipadmusicsm" />

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/button2"
    android:layout_marginLeft="5dp"
    android:layout_toRightOf="@+id/button1"
    android:background="@drawable/ipadfamilysm" />

<Button
    android:id="@+id/button4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button3"
    android:layout_alignTop="@+id/button1"
    android:background="@drawable/ipadyouthsm" />

<Button
    android:id="@+id/button5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/button4"
    android:layout_below="@+id/button3"
    android:layout_marginTop="14dp"
    android:background="@drawable/ipadlinkssm" />

<Button
    android:id="@+id/button6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button5"
    android:layout_alignBottom="@+id/button5"
    android:layout_toLeftOf="@+id/button4"
    android:background="@drawable/ipadpodcastsm" />

 </RelativeLayout>
4

1 に答える 1

2

各ボタンに固定 dp を指定しました。デバイスによって解像度が異なります。

最小限の作業で複数のデバイスでこれを機能させるには、ルートとして別の相対レイアウトを追加し、重力を中心に設定することをお勧めします。このように、レイアウトは常に画面の中央にあります。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:background="@drawable/mainback">
   <RelativeLayout 
   android:layout_width="wrap_content"
   android:layout_height="wrap_content">

      *** Your buttons would be here ***

    </RelativeLayout>
</RelativeLayout>

別の方法は、画面サイズごとに dimens ファイルを作成することですが、おそらく上記の方法が最も簡単な方法です。

于 2012-07-29T04:09:45.013 に答える