2016-08-09 69 views
0

Okay Problem zuerst, ich habe ein Hintergrundbild, das eine Art von Rahmen hat, die ein bestimmtes Layout übereinstimmen muss.Box in einem Layout

Mein aktueller Ansatz war, in einem Layout zu boxen, vielleicht gibt es eine ganz andere Lösung.

Also 15% Marge links & rechts, 10% Marge unten & oben, ich habe bereits den linken und rechten Rand, den Code unten, aber ich habe auch zu kämpfen, passen Sie auch den oberen und unteren Rand im gleichen Layout.

enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <RelativeLayout 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="0.15" /> 
    <RelativeLayout 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="0.7"> 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <Button 
       android:text="Button1 " 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/btn1" /> 
      <Button 
       android:text="Button2 " 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/btn2" />  
      <Button 
       android:text="Button3" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/btn3" />     
     </LinearLayout> 
    </RelativeLayout> 
    <RelativeLayout 
     android:layout_width="0dip" 
     android:layout_height="fill_parent" 
     android:layout_weight="0.15" /> 
</LinearLayout> 
+0

do u das Feld in der Mitte des Bildschirms setzen wollen, so dass die Margen gleich sein wird, beide Seiten ? – Maysara

+0

Sagen wir Nein, dies sollte für verschiedene Bilder verwendbar sein, ich habe den gleichen Rand nur für Testzwecke verwendet, so dass es einfacher ist, Fehler in dieser Hinsicht herauszufiltern. –

Antwort

2

können Sie PercentRelativeLayout für Prozentgrößen verwenden, wie diese

<android.support.percent.PercentRelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<ImageView 
    app:layout_widthPercent="50%" 
    app:layout_heightPercent="50%" 
    app:layout_marginTopPercent="25%" 
    app:layout_marginLeftPercent="25%"/> 

</android.support.percent.PercentRelativeLayout> 
+0

Arbeitete wie ein Charme, danke! –

+0

sind herzlich willkommen :)) –