2017-02-14 5 views
1

私はAndroidレイアウトに苦労しています。フラグメントをリストビューの下に配置

トップに、次にリストビューのボタンを含むリニアレイアウトを作成したいと思います。リストビューのすべての要素が表示されたら、Googleマップを表示するフラグメントを表示します。

これはレイアウトxmlファイルです。その場合、あなただけの断片とボタンではなく、リストビュー

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

ためlayout_weight=1追加0dpを使用してのheightためListView? – raktale

+0

リストビューにボタンを保持するヘッダーを追加します。 Googleマップを保持するリストビューにフッターを追加します。 – nnn

+0

@MichaelMeyer 'ListView'に' wrap_content'を使ってみましたが、 'fragment'に' 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

を。で 私の代わりに私がwrap_contentを使用して、リストビューにフッターとしての断片を追加することができ、私の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> 
関連する問題