0

讓我簡單解釋一下我正在嘗試做什麼。我從Yelp處找到一家餐廳,並將餐廳的屬性放入CardView中。我想要CardView的原因是因爲我想要滑動功能。我想要能夠左右滑動。 To do this, I need a RecyclerView to handle every direction (or so I've come to understand from reading this).如果有人有更好的方法來做到這一點,請讓我知道。Android MapView不填充CardView內的父母

由於某些原因,當您將MapView的layout_height設置爲具體值時,它的大小調整良好。但它不會填滿父母。

我不想爲明顯的兼容性問題設置具體的值。

此外,是否可以禁用在CardView的MapView部分上刷卡?

因此,這裏有我的佈局文件:

fragment_main.xml

<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:showIn="@layout/activity_main" 
    tools:context=".MainActivityFragment"> 

    <RadioGroup 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentTop="true" 
     android:id="@+id/radioGroup"> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Use Zip Code" 
      android:id="@+id/useZip" 
      android:checked="false" /> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Use Location" 
      android:id="@+id/useLocation" 
      android:checked="false" /> 
    </RadioGroup> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:inputType="number" 
     android:ems="10" 
     android:id="@+id/zipcode" 
     android:hint="zip code" 
     android:layout_below="@+id/radioGroup" 
     android:layout_centerHorizontal="true" 
     android:visibility="gone" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Generate" 
     android:id="@+id/generate" 
     android:layout_gravity="bottom|center_horizontal" 
     android:layout_below="@+id/zipcode" 
     android:layout_centerHorizontal="true" /> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_centerHorizontal="true" 
     android:layout_below="@+id/generate" 
     android:layout_alignParentBottom="true"> 

     <android.support.v7.widget.RecyclerView 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:id="@+id/container"> 

     </android.support.v7.widget.RecyclerView> 

    </LinearLayout> 

</RelativeLayout> 

restaurant_item.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/restaurantContainer" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:map="http://schemas.android.com/tools"> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="horizontal"> 

      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 

       <ImageView 
        android:layout_width="@dimen/_75sdp" 
        android:layout_height="@dimen/_75sdp" 
        android:id="@+id/thumbnail" 
        android:layout_margin="@dimen/_5sdp"/> 

       <ImageView 
        android:layout_width="@dimen/_75sdp" 
        android:layout_height="@dimen/_15sdp" 
        android:id="@+id/rating" 
        android:layout_margin="@dimen/_5sdp"/> 
      </LinearLayout> 

      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 

       <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceLarge" 
        android:id="@+id/name" 
        android:gravity="top" 
        android:layout_margin="@dimen/_5sdp"/> 

       <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:id="@+id/categories" 
        android:layout_margin="@dimen/_5sdp"/> 
      </LinearLayout> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

      <com.google.android.gms.maps.MapView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:id="@+id/mapView" 
       map:mapType="normal" 
       map:liteMode="true" 
       map:cameraZoom="14"/> 

     </LinearLayout> 

    </LinearLayout> 

</android.support.v7.widget.CardView> 

這裏的問題的截圖:

enter image description here

+0

父母的大小是多少?您的CardView高度爲'fill_parent'。您應該設置一些高度或將其設置爲wrap_content。 – Sharj

+0

@Sharj是誰的家長?如果你的意思是RecyclerView,它被設置爲'fill_parent'。我試着將CardView的高度設置爲'wrap_content',沒有改變,就像上面的截圖一樣。 – ctzdev

+0

可以將CardView高度設置爲200dp並將MapView設置爲'fill_parent'。這樣它將填充剩餘高度,您可以調整CardView高度。或者將CardView高度設置爲'wrap_content',然後提供您的MapView高度,如200dp(或任何您想要的高度)。 – Sharj

回答

1

可以設置CardView高度可以說200dp和MapView爲fill_parent。

這樣它會填充剩餘高度,您可以調整CardView高度。或將CardView高度設置爲wrap_content,然後提供您的MapView高度,如200dp(或您想要的任何高度)。

更新:RecyclerView是一個滾動視圖。這意味着它有無限的高度,每張卡片都應該有自己的高度,卡片不能有fill_parent

現在,如果你想讓你的MapView有其餘的高度。我假設你是指卡片高度的其餘部分。首先,你必須定義你想要你的卡多久。例如:如果您將卡片高度設置爲500dp,則MapView爲fill_parent,而CardView內的MapView以外的內容爲100dp,則MapView會佔用其餘的高度(400dp)。

如果您希望MapView在手機屏幕上留下高度,那麼您必須刪除RecyclerView並使用Card。

+0

只需將卡片向左,向右和向上滑動?這主要是爲什麼我實現了RecyclerView。 – ctzdev

+0

也許有一種方法,但我不知道。你可以發佈一個新的問題,但是。 – Sharj