2016-06-22 9 views
1

私はあなたがプレイできる4つのレベル/モードで簡単なレイアウトを持っています。問題は、私は別の画面上でレイアウトをプレビューするとき、それは同じ表示されないサイズである: Imageレイアウトをさまざまな画面サイズにするにはどうすればいいですか?

ここレイアウトコードです:

<?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" 
    android:background="#000000"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="120dp" 
     android:text="play" 
     android:gravity="center" 
     android:textSize="50sp" 
     android:id="@+id/one" 
     android:layout_alignParentTop="true" 
     android:background="@drawable/mode1background" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:textColor="#000000" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="120dp" 
     android:text="play" 
     android:gravity="center" 
     android:textSize="50sp" 
     android:id="@+id/two" 
     android:background="@drawable/mode2background" 
     android:layout_below="@+id/one" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentLeft="true" 
     android:textColor="#000000" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="120dp" 
     android:text="play" 
     android:gravity="center" 
     android:textSize="50sp" 
     android:id="@+id/three" 
     android:background="@drawable/mode3background" 
     android:layout_below="@+id/two" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:textColor="#000000" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="120dp" 
     android:text="play" 
     android:gravity="center" 
     android:textSize="50sp" 
     android:id="@+id/four" 
     android:background="@drawable/mode4background" 
     android:layout_below="@+id/three" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:textColor="#000000" /> 

</RelativeLayout> 

は、どのように私は、各TextViewは、画面サイズの4分の1も作ることができます。

+0

http://stackoverflow.com/questions/29025843/android-devices-with-different-height-takes-same-layout-folder/29026085#29026085 –

+0

これを試してみるあなたが試してみました'LinearLayout'は、プロパティが' android:weight = {value} 'であるため –

答えて

3

の解像度に応じて、 。このような

何か:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="#000000" 
       android:orientation="vertical"> 

    <TextView 
     android:id="@+id/one" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.25" 
     android:background="@drawable/mode1background" 
     android:gravity="center" 
     android:textColor="#000000" 
     android:textSize="50sp"/> 

    <TextView 
     android:id="@+id/two" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.25" 
     android:background="@drawable/mode2background" 
     android:gravity="center" 
     android:textColor="#000000" 
     android:textSize="50sp"/> 

    <TextView 
     android:id="@+id/three" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.25" 
     android:background="@drawable/mode3background" 
     android:gravity="center" 
     android:textColor="#000000" 
     android:textSize="50sp"/> 

    <TextView 
     android:id="@+id/four" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.25" 
     android:background="@drawable/mode4background" 
     android:gravity="center" 
     android:textColor="#000000" 
     android:textSize="50sp"/> 

</LinearLayout> 

LinearLayoutとレイアウトの重量に開発者のガイドをチェックアウト: https://developer.android.com/guide/topics/ui/layout/linear.html

+0

他の回答が示唆するように、layout_weightが0.25または1であるべきですか? 0.25と1をワイトとして使うように見えるので、違いは何ですか。 –

+0

同じものであれば長い間は関係ありません。私はちょうど私の体重の合計が1のときに好きです:) – earthw0rmjim

+0

合計が4(重み1の場合)と1(0.25の場合)で異なるわけではありません –

0

描画可能MDPI

描画可能-hdpi

描画可能xhdpi

描画可能LDPI

をresourcefolderに次のディレクトリを作成し、それぞれのディレクトリに背景の異なる解像度の画像を配置

drawable-xxhdpi

描画可能xxxhdpi

ノートすべてのフォルダ内の画像の名前が同じである必要があり、アンドロイドは自動的にそれぞれのフォルダから画像を選択しますあなたはandroid:layout_weight属性を持つ垂直LinearLayoutを使用することができ、電話

2

垂直方向とLinearLayoutに変更し、親のレイアウトを。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="1"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="2"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="3"/> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:text="4"/> 

</LinearLayout> 
+0

layout_weightは1か0かですか?他の答えが示唆しているように25? 0.25と1をワイトとして使うように見えるので、違いは何ですか。 –

+0

親にweightSumを定義しないと、違いはありません。 – Niko

0

あなたが垂直oreintationと属性を与えることでリニアレイアウトを使用する必要がありますデバイスの全高を占めるようにしたいと「layout_weight:次に1

例に0dpと重量にそれぞれの子の高さを設定'=すべてのTextViewに対して1。 サンプルコード

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#000000" 
    android:orientation="vertical"> 

    <TextView 
     android:id="@+id/one" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_weight="1" 
     android:background="@drawable/mode1background" 
     android:gravity="center" 
     android:text="play" 
     android:textColor="#000000" 
     android:textSize="50sp" /> 

    <TextView 
     android:id="@+id/two" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_below="@+id/one" 
     android:layout_weight="1" 
     android:background="@drawable/mode2background" 
     android:gravity="center" 
     android:text="play" 
     android:textColor="#000000" 
     android:textSize="50sp" /> 

    <TextView 
     android:id="@+id/three" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_below="@+id/two" 
     android:layout_weight="1" 
     android:background="@drawable/mode3background" 
     android:gravity="center" 
     android:text="play" 
     android:textColor="#000000" 
     android:textSize="50sp" /> 

    <TextView 
     android:id="@+id/four" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_below="@+id/three" 
     android:layout_weight="1" 
     android:background="@drawable/mode4background" 
     android:gravity="center" 
     android:text="play" 
     android:textColor="#000000" 
     android:textSize="50sp" /> 

</LinearLayout> 
関連する問題