2014-09-19 137 views
0

我有一個包含一個地址,一些按鈕和一個地圖,我想顯示在以下格式的部分滾動型:MapFragment不尊重matchparent

Template

下面是結果我得到相反:

enter image description here

出於某種奇怪的原因,我不能強迫MapFragment尊重matchparent屬性,它總是原來是一個特定的默認他飛行。這裏是基本的XML:

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/tile_view" 
     android:orientation="vertical" 
     android:padding="10dp"> 

     <!-- Address --> 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="@style/agencyAddress"/> 

     <!-- Map and Buttons --> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:baselineAligned="false" 
      android:paddingTop="5dp"> 

      <!-- Map --> 
      <fragment 
       android:id="@+id/agency_map" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_toRightOf="@+id/buttons" 
       android:layout_toEndOf="@+id/buttons" 
       class="com.google.android.gms.maps.MapFragment" /> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/buttons" 
       android:orientation="vertical"> 

       <ImageButton 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/random_image" 
        android:src="@drawable/random_image"/> 

       <ImageButton 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:id="@+id/random_image2" 
        android:src="@drawable/random_image"/> 

      </LinearLayout> 

     </RelativeLayout> 

    </LinearLayout> 
+0

嘗試在另一個佈局包裹碎片,像LinearLayout中,然後匹配與你的RelativeLayout? – nem035 2014-09-19 20:10:09

+0

不幸的是,既不能使用RelativeLayout也不能使用LinearLayout。 – 2014-09-19 20:16:22

回答

0

將這兩個屬性添加到佈局中的nap片段。

android:layout_alignTop="@+id/buttons" android:layout_alignBottom="@+id/buttons"

+0

也不起作用。我也嘗試過'alignParentBottom'和'alignParentTop'。 – 2014-09-19 20:39:30

0

您的代碼似乎有點關閉。在線性佈局中很難捕捉到你想要做的事情。 ImageView將是你的片段。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
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:paddingTop="@dimen/activity_vertical_margin" 
android:paddingBottom="@dimen/activity_vertical_margin" 
tools:context=".MyActivity$PlaceholderFragment"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/ic_launcher" 
    android:orientation="vertical"> 

    <!-- Address --> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Some Text" 
     android:gravity="center" 
     android:textSize="20dp"/> 

    <!-- Map and Buttons --> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:baselineAligned="false" 
     android:layout_gravity="center" 
     android:padding="5dp"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/buttons" 
      android:orientation="vertical"> 


      <ImageButton 
       android:layout_width="75dp" 
       android:layout_height="75dp" 
       android:id="@+id/random_image" 
       android:src="@drawable/ic_launcher" 
       /> 

      <ImageButton 
       android:layout_width="75dp" 
       android:layout_height="75dp" 
       android:id="@+id/random_image2" 
       android:layout_below="@id/random_image" 
       android:src="@drawable/ic_launcher"/> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_toRightOf="@id/random_image" 
       android:layout_alignBottom="@id/random_image2" 
       android:layout_marginBottom="5dp" 
       android:layout_marginTop="5dp" 
       android:background="#000000"/> 


     </RelativeLayout> 

    </RelativeLayout> 

</LinearLayout> 

+0

對不起,如果我誤解了,但片段去了哪裏? – 2014-09-19 20:50:08

+0

您的片段是我在按鈕下用作ImageView的片段。我沒有說清楚。抱歉 – chr1st3nd0 2014-09-19 20:54:17