Reputation: 676
Let me briefly explain what I'm trying to do. I am getting a restaurant from Yelp and putting the restaurant's attributes into a CardView. The reason I want a CardView is because I want swiping functionality. I want to be able to swipe left, right, and up. To do this, I need a RecyclerView to handle every direction (or so I've come to understand from reading this). If someone has a better way to do this please let me know.
For some reason, when you set MapView's layout_height
to a concrete value, it resizes fine. But it won't fill the parent.
I don't want to set a concrete value for obvious compatibility issues.
Also, is it possible to disable swiping on the MapView part of the CardView?
So here are my layout files:
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>
Here's a screenshot of the problem:
Upvotes: 0
Views: 1044
Reputation: 15798
Either set CardView
height to let's say 200dp
and MapView to fill_parent.
This way it will fill remaining height, you can adjust CardView
height. or set CardView
height to wrap_content and then provide your MapView
height like 200dp
(or whatever height you want).
Update: RecyclerView is a scroll view. Which means it has infinite height and every Card you put in it should have it's own height, card can't have fill_parent
.
Now if you want your MapView to have rest of the height. I assume you mean rest of the Card height. For this first you have to define how long you want your Card to be.
Ex: If you set your Card height to 500dp, MapView to fill_parent and your content other than MapView inside Card is 100dp then MapView will take rest of the height (400dp).
If you want MapView to take rest of the height on the mobile screen then you have to remove RecyclerView and just use Card.
Upvotes: 1