2016-04-07 14 views
1

Hallo, ich bin ein bisschen Stumpf jetzt. Ich dachte, das ist in Android XML möglich.Machen Sie Ansicht füllen Sie die Lücke in der Mitte, aber hinterlässt Platz zu seinen unteren Geschwister

Ich wollte ein Layout wie diese machen:

enter image description here

Das Problem ist, die kleinen zwei Elemente, die nebeneinander sind. Wenn ich die Ansicht Nr. 2 an die Höhe anpasse, erwarte ich, dass sie auch den Platz ihrer anderen Geschwister respektiert. Ich lag falsch, aber ich verstehe es jetzt. Wenn ich die layout_Height der Ansicht # 2 auf "match_parent" einstelle, belegt sie den verbleibenden Platz und die Ansicht # 3 und die Ansicht # 4 werden in den untersten Teil gelegt und sind auf dem Bildschirm nicht mehr sichtbar.

Ich möchte, dass Ansicht # 2 in der Mitte erweitert wird, aber immer noch Platz für Ansicht # 3 und Ansicht # 4 und einige Elemente darunter und nicht weit nach unten geschoben werden. Hier

ist, was ich jetzt tue:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:fitsSystemWindows="true" 
    tools:context=".TaskActivity"> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/textinput_layout_note_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:paddingTop="16dp"> 

     <EditText 
      android:id="@+id/edittext_task" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:singleLine="true" 
      android:textSize="32sp" 
      android:padding="8dp" 
      android:hint="@string/edittext_task_title_hint"/> 

    </android.support.design.widget.TextInputLayout> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/textinput_layout_note_description" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/textinput_layout_note_title"> 

     <EditText 
      android:id="@+id/edittext_todo" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:maxLines="1" 
      android:gravity="top" 
      android:hint="@string/edittext_task_content_hint"/> 

    </android.support.design.widget.TextInputLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textinput_layout_note_description" 
     android:orientation="horizontal"> 

     <ImageButton 
      android:id="@+id/imagebutton_insert_note" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_content_add_black" 
      android:contentDescription="@string/content_description_choose_note" 
      style="?android:attr/borderlessButtonStyle" /> 

     <ImageButton 
      android:id="@+id/imagebutton_expand_note" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:src="@drawable/ic_open_in_new_black_24dp" 
      android:contentDescription="@string/content_description_expand_note" 
      style="?android:attr/borderlessButtonStyle" /> 

    </LinearLayout> 

</RelativeLayout> 

ich verwendet habe, mit Linearlayout layout_weight kombiniert, aber das wird immer langsamer, als ich einige verschachtelte Ansichten haben, die auch Gewicht erfordert. Ich wollte, dass das relativ gemacht wird.

Irgendwelche Ideen, wie ich dieses Layout erreichen kann?

Vielen Dank!

Antwort

1

Ich wollte das relativ gemacht werden.

RelativeLayout ist keine magische Kugel für die Leistung.

Irgendwelche Ideen, wie ich dieses Layout erreichen kann?

Versuchen:

<RelativeLayout 
    ...> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/textinput_layout_note_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:paddingTop="16dp"> 

     ... 

    </android.support.design.widget.TextInputLayout> 

    <android.support.design.widget.TextInputLayout 
     android:id="@+id/textinput_layout_note_description" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/textinput_layout_note_title" 
     android:layout_above="@+id/whatever_this_thing_is"/> 

     ... 

    </android.support.design.widget.TextInputLayout> 

    <LinearLayout 
     android:id="@id/whatever_this_thing_is" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal"> 

     ... 

    </LinearLayout> 

</RelativeLayout> 

(wo die ... Bits für das Material sind Sie bereits haben, entfernt die Auflistung kürzer zu halten)

IOW:

  • Anker oben Blick nach oben
  • Verankern Sie die Ansicht von unten nach unten
  • Anker die mittlere Sicht unter dem oberen und über dem Boden sein, es zu strecken wodurch den Zwischenraum
+0

Hallo @CommonsWare, was ist, wenn ich andere Ansichten direkt unter Ansicht 3 und 4 habe. Ich habe meine in letzter Zeit versucht, aber habe es nicht zur Arbeit. Der beste Weg, über den ich nachdenken könnte, ist, alles in zwei Teilen durch ein lineares Layout zu trennen. Aber ich bin fasziniert, wenn dies für RelativeLayout überhaupt möglich ist? –

+1

@NeonWarge: Aus dem Stegreif, haben diese 'android: layout_alignParentBottom =" true "'.Habe das 'LinearLayout', das ich als' whatever_this_thing_is' identifiziert habe, 'android: layout_above', das neue Zeug. Alles andere würde so bleiben wie es ist. – CommonsWare

1

versuchen, diesen Ansatz zu füllen!, Ich habe es nicht in Android-Studio versucht, aber es sollte Mache den Trick.

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <View 
     android:id="@+id/viewTop" 
     android:layout_width="match_parent" 
     android:layout_height="120dp" 
     android:layout_alignParentTop="true"/> 

    <View 
     android:id="@+id/viewMiddle" 
     android:layout_above="@id/viewBottom" 
     android:layout_below="@id/viewTop" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

    <LinearLayout 
     android:id="@+id/viewBottom" 
     android:layout_width="match_parent" 
     android:layout_height="120dp" 
     android:layout_alignParentBottom="true"> 

     <View 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="50"/> 

     <View 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="50"/> 

    </LinearLayout> 

</RelativeLayout> 
Verwandte Themen