2013-10-29 24 views
8

ちょっと、画面上部から少し下までスクロールビューを表示しています。これは広告バナーが表示される場所です。私はこれらの要素の間に(ボタンとバナーの間に)Googleのポリシーのためにいくつかのピクセルを持っていたい。これまで私はdpの値を設定してこれを行いました。しかし、デバイスが異なると、一部の高解像度電話機では広告とスクロールビューとの間に大きなギャップが生じます。これは私が設定したい理由ですAndroidで画面サイズをXMLで取得

<ScrollView 
android:layout_height="(Screen_height-banner)-5px" 

(もちろん私も、これは何のコードではないとして、この方法でそれをしようとしなかったが、私はそれがかなりよく、私が行う予定何を合計すると思います)

ありがとうございます!

答えて

2

layout_aboveは、あなたがRelativeLayoutを使用してこれを行うと、使用することができます使用alignmentsmargins 。あなたのケースで

Screen_height-バナーが画面の高さを表しており、あなたが一番下にそれを配置し、あなたの代わりにスクロールビューを拡張する必要がある場合は、あなたのXMLが

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

     <ScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom" 
      android:layout_marginBottom="5dp"> 

</RelativeLayout > 

だろう端から5DPセパレータを作りたい場合それはあなたのxmlになるでしょう

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding_bottom="5dp"> 

     <ScrollView 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent"> 

</RelativeLayout > 
+0

API APIレベル8以上は「fill_parent」を「match_parent」に置き換えました。 – Antonin

1

使用RelativeLayoutは、5pxのマージンを設定し、それが実行時に実行されませんので、あなたがXMLで画面サイズを照会することはできません

2

あなたはユーザーの重みパラメータを設定できます。両方のレイアウトのウェイトを0.5に設定すると、これらのレイアウトの画面幅が同じになります。

<LinearLayout 
    android:id="@+id/alt_panel" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/orta_panel" > 

    <LinearLayout 
     android:id="@+id/altsol_panel" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="0.5" 
     android:gravity="center_horizontal" 
     android:orientation="vertical" > 


    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/altsag_panel" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="0.5" 
     android:gravity="center_horizontal" 
     android:orientation="vertical" > 


    </LinearLayout> 
</LinearLayout>