Add a view overlay on map view android - android

I am using the MapView from the Google Map Android SDK in full screen, but I have a requirement to display another transparent full view over the mapview. The overlay displays as expected, however, the map can be controlled (markers can be clicked, map can be moved) despite the overlay being on it.
How can I ensure the overlay prevents the map from being controllable when in view?

Add following on your overlay view parent layout.
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"
Remember you need to place above line on parent layout of overlay view

You can do this by making your overlay clickable. Add below code to the xml of your overlayview.
android:clickable="true"

For example I use the following code to add a button to the page
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="#+id/location_map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#359c5e"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:padding="8dp"
android:layout_margin="5dp"
android:text="#string/go"
android:textColor="#ffffff" />
</RelativeLayout>

Related

Custom keyboard with custom row

I have to draw custom view (image view + edit text) on top of keyboard in my custom keyboard app. how can i draw this?
I used many custom keyboard example but using that i was just able to draw custom keys (Alphabets/Numeric).
Please help me
Edit-
I tried to create with custom keyboard and added a sample view above keyboardview but when i run the app it is not visible
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/layoit_row"
android:layout_width="match_parent"
android:layout_height="100dp">
<ImageView
android:id="#+id/ivKeyboard"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:padding="10dp"
android:scaleType="fitEnd"
android:src="#drawable/ic_launcher_background" />
<EditText android:id="#+id/et_box"
android:layout_toRightOf="#+id/ivKeyboard"
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="Asjhish"/>
</RelativeLayout>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/layoit_row"
android:keyPreviewLayout="#layout/preview" />

Map Fragment Resize

I am quite new to Android Development and have been following guides.
I have a drawer layout with different fragments for each of the different screens.
Inside 1 of the fragment is another SupportMapFragment which I am using for Google Maps.
The thing with this is that once I place the fragment inside the linear layout, I cannot place button or item after it as it fills to the bottom of the screen.
<RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:orientation="vertical">
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp" />
<Button
android:id="#+id/btn_submitReport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Button" />
</LinearLayout>
</RelativeLayout>
I can change the fragment height to 350dp and it will obviously work but I was wondering if it can be done automatically so that for larger devices it will be longer with the button lower down etc.
What I basically am trying to achieve
Thanks

Apply Material ripple to ViewPager item

I would like to add a Material design ripple effect to the Views shown by a ViewPager. My team has been able to do that in other parts of our app by setting ?attr/selectableItemBackground as the background of a View. However, when I assign that as the background of the View returned by my ViewPager's adapter, the effect doesn't seem to work. Has anyone gotten that to work?
From experience, it seems that ViewPagers consume events that prevent certain interactions with their children. For example, ViewPager items don't get onClick() events and you have to work around that in other ways. I wonder if there isn't a similar issue here, where the ViewPager is consuming events that are needed for the ripple to work.
You simply have to put your xml view into a FrameLayout like this:
old layout:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/viewpager_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:scaleType="centerCrop"/>
<ProgressBar
android:id="#+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:indeterminateDrawable="#drawable/progress_medium_holo"
android:visibility="gone" />
</RelativeLayout>
new layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
android:selectable="true">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/viewpager_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/app_name"
android:scaleType="centerCrop"/>
<ProgressBar
android:id="#+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:indeterminateDrawable="#drawable/progress_medium_holo"
android:visibility="gone" />
</RelativeLayout>
</FrameLayout>
The view pager is intended for swiping, so if you want to click it, you need to specify that, either programmatically, or in the XML file. For instance, add these attributes to the layout of the item of your view pager, not the view pager itself.
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"

Adding custom footer buttons to Google Maps Marker on Android

When I click on a Marker inside a MapFragment, two buttons appear on the bottom of the map (for route and search). How can I customize those buttons?
I searched for some tips here but only find how to add buttons to the info window...
Thanks.
You can use a FrameLayout with 3 children, and set the android:visibility of the bottom buttons to invisible.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
/>
<Button
android:layout_gravity="bottom|left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:text="Button 1"/>
<Button
android:layout_gravity="bottom|right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:text="Button 2"
/>
</FrameLayout>
(If you dont set the android:visibility="invisible", you can see these 2 buttons in the bottom of your mapFragment, see image below)
In your onMarkerClick method, you can change the invisibility of the these 2 buttons to visible, sample code:
button1.setVisibility(View.VISIBLE);
button2.setVisibility(View.VISIBLE);

how to show TextView,Buttons On MapView (To Overlap On It)..?

In my application i have mapview and I want to show distance in a textview and also a Button ,
I have done this.and tried this..
http://www.anddev.org/post3452.html#p3452
PROBLEM IS>>>>
I WANT TO SHOW TEXTVIEW AND BUTTON OVER THE MAP VIEW..
so I can See MAPVIEW in Full Screen..with other items over it(as we can see map through textview)..
Any SPECIFICATION NEEDED TO BE DONE IN xml FILE..??
Please..Reply me..
Thank You..in advance
Yes you can do that.
For eg:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:id="#+id/mapView" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:enabled="true"
android:layout_centerInParent="true" android:clickable="true"
android:apiKey="your api key" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Click"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" android:id="#+id/clickBtn" />
</RelativeLayout>
create a layout with the RelativeLayout and embed the map view in it. Once set, set the relative position of your components as per your need.

Categories

Resources