2016-12-02 4 views
0

Ich habe ein kleines Beispiel erstellt, um mein Problem zu erklären. Im Beispiel habe ich ein RelativeLayout erstellt, das den gesamten Bildschirm ausfüllt. Und 3 Kinder:Wie füllen Sie den gesamten Platz im übergeordneten relativen Layout?

  1. FrameLayout mit id Mitte, die alle leeren Raum ohne Overlay auf Ober- und Unterseite des FrameLayout (pink)
  2. FrameLayout mit id oben füllen müssen, die über Mitte (rot)
  3. FrameLayout zeigen müssen mit id Unterseite, die unter dem mittleren (gelb)

Layout zeigen müssen:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:id="@+id/top" 
     android:layout_width="100dp" 
     android:layout_height="24dp" 
     android:layout_above="@id/middle" 
     android:background="#FFFF0000" /> 

    <FrameLayout 
     android:id="@+id/middle" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#FFFF00FF" /> 

    <FrameLayout 
     android:id="@+id/bottom" 
     android:layout_width="100dp" 
     android:layout_height="24dp" 
     android:layout_below="@id/middle" 
     android:background="#FFFFFF00" />  

</RelativeLayout> 

Screenshot von meinem Beispiel Ergebnis:

enter image description here

Und der Screenshot, was ich tun muss:

enter image description here

+0

Musst du 'RelativeLayout' verwenden? –

Antwort

0

Okay, dieser Code sollte es tun.

Check it out:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<FrameLayout 
    android:id="@+id/top" 
    android:layout_width="100dp" 
    android:layout_height="24dp" 
    android:background="#FFFF0000" 
    android:layout_alignParentTop="true" /> 
<FrameLayout 
    android:id="@+id/bottom" 
    android:layout_width="100dp" 
    android:layout_height="24dp" 
    android:background="#FFFFFF00" 
    android:layout_alignParentBottom="true" /> 
<FrameLayout 
    android:id="@+id/middle" 
    android:layout_above="@id/bottom" 
    android:layout_below="@id/top" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="#FFFF00FF" /> 
</RelativeLayout> 
+0

Danke, es ist eine gute Lösung – Anton111111

0

ich das hoffen, dass Sie

helfen
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout 
     android:id="@+id/top" 
     android:layout_width="100dp" 
     android:layout_height="24dp" 
     android:background="#FFFF0000" 
     android:layout_alignParentTop="true" 
     /> 

    <FrameLayout 
     android:id="@+id/middle" 
     android:layout_above="@+id/bottom" 
     android:layout_below="@+id/top" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#FFFF00FF" /> 
    <FrameLayout 
     android:id="@+id/bottom" 
     android:layout_width="100dp" 
     android:layout_height="24dp" 
     android:background="#FFFFFF00" 
     android:layout_alignParentBottom="true" 
     /> 

</RelativeLayout> 
0

So etwas sollte funktionieren:

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <FrameLayout 
     android:id="@+id/middle" 
     android:layout_marginTop="24dp" 
     android:layout_marginBottom="24dp" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#FFFF00FF" /> 

    <FrameLayout 
     android:id="@+id/top" 
     android:layout_width="100dp" 
     android:layout_height="24dp" 
     android:background="#FFFF0000" /> 

    <FrameLayout 
     android:id="@+id/bottom" 
     android:layout_width="100dp" 
     android:layout_height="24dp" 
     android:layout_gravity="bottom" 
     android:background="#FFFFFF00" /> 

</FrameLayout> 
0

Statt RelativeLayout verwenden Sie LinearLayout und nutzen layout_weight zu füllen den verbleibenden Raum nutzen können.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<FrameLayout 
    android:id="@+id/top" 
    android:layout_width="100dp" 
    android:layout_height="24dp" 
    android:background="#FFFF0000" /> 

<FrameLayout 
    android:id="@+id/middle" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:background="#FFFF00FF" 
    android:layout_weight="1"/> 

<FrameLayout 
    android:id="@+id/bottom" 
    android:layout_width="100dp" 
    android:layout_height="24dp" 
    android:background="#FFFFFF00" /> 

</LinearLayout> 
0

Um dies zu tun mit relativem Layout müssen Sie obere und untere Layouts Grenzen ausrichten, und als das mittlere Layout in Beziehung zwischen ihnen eingestellt.

Siehe unten:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="pl.orbitemobile.myapplication.MainActivity"> 


      <FrameLayout 
       android:id="@+id/top" 
       android:layout_width="100dp" 
       android:layout_height="24dp" 
       android:layout_alignParentTop="true" 
       android:background="#FFFF0000" /> 

      <FrameLayout 
       android:id="@+id/middle" 
       android:layout_width="match_parent" 
       android:layout_height="fill_parent" 
       android:layout_below="@id/top" 
       android:layout_above="@+id/bottom" 
       android:background="#FFFF00FF" /> 

      <FrameLayout 
       android:layout_width="100dp" 
       android:id="@+id/bottom" 
       android:layout_height="24dp" 
       android:layout_alignParentBottom="true" 
       android:background="#FFFFFF00" /> 

</RelativeLayout> 

Wirkung:

enter image description here

Verwandte Themen