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