2017-02-14 2 views
1

Ich habe Probleme mit meinem Android Layout.Fragment unter Listview platzieren

Ich möchte ein lineares Layout erstellen, das oben eine Schaltfläche enthält, dann eine Listenansicht, und wenn alle Elemente der Listenansicht angezeigt werden, möchte ich ein Fragment anzeigen, das Google Maps anzeigt.

Dies ist meine Layout-XML-Datei. In diesem Fall können Sie nur das Fragment und das Button sehen, aber nicht die Listenansicht

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:paddingLeft="10dp" 
       android:paddingRight="10dp" 
       android:orientation="vertical" 
     tools:context="de.mypackage.MyActivity"> 

    <Button 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:layout_weight="0" 
      android:id="@+id/button_back" 
      android:text="@string/back" 
      /> 

     <ListView 
       android:id="@+id/list" 
       android:layout_height="fill_parent" 
       android:layout_width="fill_parent" 
       android:layout_weight="1"/> 
       /> 

    <fragment 
      android:id="@+id/fragement" 
      android:name="de.mpackage.MapsFragment" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:layout_weight="0" 
      tools:layout="@layout/fragment_maps"/> 

</LinearLayout> 

Jede Idee, wie ich mein Layout realisieren kann?

+1

Können Sie Fragment als Fußzeile zur Listenansicht hinzufügen? – raktale

+0

Fügen Sie Ihrer Listenansicht einen Header hinzu, der die Schaltfläche enthält. Fügen Sie Fußzeile zu Ihrer Listenansicht hinzu, die Google Maps enthält. – nnn

+0

@MichaelMeyer Ich habe versucht, 'wrap_content' für die' ListView' zu verwenden und einfach 'layout_weight = 1' in' fragment' zu setzen. Ich habe die Antwort gepostet. Ich hoffe es hilft. :) – natsumiyu

Antwort

0

diesen Code Versuchen

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp"> 

    <Button 
     android:id="@+id/button_back" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/back" /> 

    <ListView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" /> 

    <fragment 
     android:id="@+id/fragement" 
     android:name="com.yougotag.supplierfieldagent.fragments.AboutFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     tools:layout="@layout/fragment_about_app" /> 

</LinearLayout> 
+0

Sorry, aber ich kann die Listview immer noch nicht sehen. Nur das Fragment mit Google Maps –

0

Hinweis: Erklären Sie Ihre Wurzel-Layout als RelativeLayout

RelativeLayout ist eine Ansicht, die Gruppe untergeordnete Ansichten in Bezug Positionen zeigt. Die Position jeder Ansicht kann relativ zu Geschwisterelementen angegeben werden.

Dann unterhalb der gegebenen Ankeransicht ID android:layout_below

Position der obere Rand dieser Ansicht verwendet werden. Passt den oberen Rand dieser Ansicht und den unteren Rand der Ankeransicht an. diese

<fragment 
     android:id="@+id/fragement" 
     android:name="de.mpackage.MapsFragment" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_below="@+id/birth" 
     tools:layout="@layout/list"/> 
1
Try this code 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:paddingLeft="10dp" 
    android:weightSum="1" 
    android:paddingRight="10dp"> 

    <Button 
     android:id="@+id/button_back" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/back" /> 

    <ListView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" /> 

    <fragment 
     android:id="@+id/fragement" 
     android:name="com.yougotag.supplierfieldagent.fragments.AboutFragment" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="0.5" 
     tools:layout="@layout/fragment_about_app" /> 

</LinearLayout> 

this will set both in half screen you can change ration of weights in layout. 
+0

Entschuldigung, das ist nicht das, was ich suche –

0

Versuchen:

<?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:layout_width="wrap_content" 
        android:layout_height="fill_parent" 
        android:paddingLeft="10dp" 
        android:paddingRight="10dp" 
        tools:context="de.mypackage.MyActivity"> 

      <Button 
       android:layout_height="wrap_content" 
       android:layout_width="fill_parent" 
       android:layout_weight="0" 
       android:id="@+id/button_back" 
       android:text="@string/back" 
       /> 

      <ListView 
        android:id="@+id/list" 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent" 
        android:layout_weight="1" 
        android:layout_below="@+id/button_back"/> 
        /> 

     <fragment 
       android:id="@+id/fragement" 
       android:name="de.mpackage.MapsFragment" 
       android:layout_height="wrap_content" 
       android:layout_width="fill_parent" 
       android:layout_weight="0" 
       android:layout_below="@+id/list" 
       tools:layout="@layout/fragment_maps"/> 

    </RelativeLayout> 
+0

Jetzt kann ich nur die Listenansicht sehen –

0

Ich fand eine Lösung hoffen, dass es hilft. In meinem ListView für die height statt 0dp der Verwendung verwendete ich wrap_content und fügt layout_weight=1 für meine Fragment

<LinearLayout 
    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:background="#EFEFEF" 
    android:orientation="vertical"> 

    <Button 
     android:id="@+id/button_back" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     /> 

    <ListView 
     android:id="@+id/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:divider="@null"/> 

    <fragment 
     android:name="de.mpackage.MapsFragment" 
     android:id="@+id/fragement" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_margin="5dp" 
     android:layout_weight="1" 
     /> 

</LinearLayout>