讓我簡單解釋一下我正在嘗試做什麼。我從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>
這裏的問題的截圖:
父母的大小是多少?您的CardView高度爲'fill_parent'。您應該設置一些高度或將其設置爲wrap_content。 – Sharj
@Sharj是誰的家長?如果你的意思是RecyclerView,它被設置爲'fill_parent'。我試着將CardView的高度設置爲'wrap_content',沒有改變,就像上面的截圖一樣。 – ctzdev
可以將CardView高度設置爲200dp並將MapView設置爲'fill_parent'。這樣它將填充剩餘高度,您可以調整CardView高度。或者將CardView高度設置爲'wrap_content',然後提供您的MapView高度,如200dp(或任何您想要的高度)。 – Sharj