2017-02-14 7 views
1

Я борюсь с моим макетом Android.Размещение фрагмента ниже Listview

Я хочу создать линейную компоновку, содержащую кнопку вверху, следующий вид списка и когда будут отображаться все элементы представления списка. Я хочу показать фрагмент, который отображает Карты Google.

Это мой XML-файл Layout. В этом случае вы можете увидеть только фрагмент и кнопки, но не ListView

<?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> 

Любая идея, как я могу реализовать свой макет?

+1

Вы можете добавить фрагмент в качестве нижнего колонтитула в ListView? – raktale

+0

Добавьте заголовок в свой список, который будет удерживать кнопку. Добавьте нижний колонтитул в список, в котором будут храниться Карты Google. – nnn

+0

@MichaelMeyer Я попытался использовать 'wrap_content' для' ListView' и просто поместил 'layout_weight = 1' в' фрагмент'. Я отправил ответ. Надеюсь, поможет. :) – natsumiyu

ответ

0

Попробуйте этот код

<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

извините, но я до сих пор не вижу списка. Только фрагмент с Картами Google –

0

Совет: Объявить раскладку корня, как RelativeLayout

RelativeLayout представляет собой вид группы, которая отображает дочерние представления в относительных позиций. Позиция каждого вида может быть указана как относительная к родственным элементам.

Затем с помощью android:layout_below

позиции верхнего края этой точки зрения ниже данного вида якорь ID. Вмещает верхний край этого вида и нижний край анкера.

<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

Извините, что это не то, что я ищу –

0

Попробуйте это:

<?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

Теперь я вижу только просмотр –

0

Я нашел решение надеюсь, что это помогает. В моей ListView для height вместо использования 0dp я wrap_content и добавляет layout_weight=1 для моего 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> 
Смежные вопросы