Android MapView - how to attach additional controls to a MapView in desired position - android-mapview

I need to place additional image button "my current location" to a top right corner of the MapView. Any ideas how to do this?
Making the questions generic:
1) According to MapView documentation it is possible to attach additional view objects to a MapView. How to do this?
2) How to place such additional controls into specific position on MapView?

The example below adds a button on a mapview, just copy paste it and then move the button to where you like it:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map_main"
android:orientation="vertical"
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:clickable="true"
android:apiKey="0y6Hyjz6Kxo-NOV_9KHYF7-ECYeGt99xeyVU3IQ"/>
<Button
android:id="#+id/select_3"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:text="Center on Pickup Location"
style="#style/BasicButton"
android:layout_height = "40dp"
android:layout_width = "280dp"
android:onClick="selfSelectCenterLocation">
</Button>
</RelativeLayout>

Related

Confuse about recyclerview and imageview sizes

i'm currently using a recyclerview to display a menu consisting of an image each row.
i've created the image to be 1080 x 300 in order so it can be scale down withouth mutch issue
I can't quit understand what width options to use for the RecyclerView, and for the items layouts and imageview.
I need the image view to be, around 150dp in Height and the With to ocupy the entire screen, just like on the editor
EDIT 1:
Now theres a huge empty space between rows
Use this code for ImageView in layout resource file created by yourself like custom.xml i.e. res/layout/custom.xml:
<?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="wrap_content">
<ImageView
android:id="#+id/imgItem"
android:layout_width="match_parent"
android:layout_height="150dp" />
</RelativeLayout>
Use this code for RecyclerView :
android:width="match_parent"
android:height="match_parent"
Try to change the Scale of Image View to Center Crop or Fit XY
Like This:
android:scaleType="centerCrop"
Use RecyclerView in your default activity like this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible">
<ImageView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:src= "" />
</androidx.recyclerview.widget.RecyclerView>
</RelativeLayout>
Note that the height for ImageView is wrap content. This will work fine given that the height of each image is equal

How to implement a overlapping TextView in a ImageView, which combinely works as a Button?

I am new to Android development and I need to know if I can overlap an imageView and a TextView together into a button. It should be similar to the image that I've shared and I need to frame it in a GridLayout with 2 columns. If I use FrameLayout for each imageView and textView it becomes little complex, is there any alternative method?
Try this and run...if any error occurs please tell me I will help
<?xml version="1.0" encoding="utf-8"?>
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/img_category"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/your_image"
android:scaleType="centerCrop"
android:textColor="#color/colorBlack"
android:text="Title"
android:textSize="25sp"/>
</GridLayout>

How to add ButtonOverlay on a Map(osmdroid)

I want to add a button overlay but it shouldn't be based on the geopoint but instead based on the screen. So whenever i scroll the map, the button should still exists and will remain in that position, How do i do that?
Just add it to your android layout for the activity/fragment
Example here:
https://github.com/osmdroid/osmdroid/blob/master/OpenStreetMapViewer/src/main/res/layout/sample_cachemgr.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parent_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<org.osmdroid.views.MapView
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tilesource="Mapnik" />
<Button android:id="#+id/btnCache"
android:layout_width="fill_parent"
android:text="Cache Manager"
android:layout_height="wrap_content"></Button>
</RelativeLayout>

Place WebView below GridView in Android Layout?

Below is the xml layout for my Android App. I am trying to positions a webview below the gridview on the screen.
Can anyone help explain what I need to do to get that to work?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/HomePage"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<GridView
android:id="#+id/Grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:scrollbars="vertical" />
<WebView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/webView1" />
</LinearLayout>
</LinearLayout>
Thanks
I think two minor changes will help make this work for you. First, when creating a LinearLayout, the android:orientation attribute is required to indicate whether the children should be added horizontally or vertically. Since you want one view on top of the other, add android:orientation=vertical to the HomePage LinearLayout. Second, your GridView currently has a android:layout_height of fill_parent. This will cause it to expand vertically and fill up the entirety of the LinearLayout, which will keep your WebView from being displayed. Try changing this attribute to wrap_content.
Making the height of both children wrap_content could possibly cause you to have some empty space in your app. If you need either the GridView or WebView to take up all of the empty space in the view, you can use the android:layout_weight attribute. Assign the view you want to expand to fill all remaining space after the rest are drawn the attribute like this: android:layout_weight=1. (Here, the 1 represents 100% of the remaining space) If you want more granular control over what percentage of the parent your children occupy, look into using decimal values with the android:layout_weight attribute or android:weightSum on the parent in conjunction with a android:layout_weight on each of the children. Hope this helps!
Use android:layout_height="wrap_content" in Gridview
Set orientation attribute in inner linear layout.
android:orientation="vertical"
Give fixed height of WebView and set android:layout_weight="" in both child.
Try below code and change according to your webview height and grid view height.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/HomePage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="2"
android:orientation="vertical">
<GridView
android:id="#+id/Grid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:layout_weight="1"
android:scrollbars="vertical" />
<WebView
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_weight="1"
android:id="#+id/webView1"
/>
</LinearLayout>
</LinearLayout>
In above code I give Height of WebView 200dp change according to your requirement.

Android: SlidingDrawer with bottomOffset and content visible

I have been experiencing some issue with the SlidingDrawer in Android. I am building a screen with a horizontal sliding drawer. It is working fine, it is opening and closing as expected. I have set a bottomOffset as 50dip in order to see 50dpi of the content when the drawer is closed, but this is not happening.
When the drawer is closed, I am seeing the 50dip distance between the right side of the screen to the handle, but then the content view gets invisible so there is a 50dip black space between the handle and the screen edge, as the image below shows:
When I press the handle button, it seems that the content gets its visibility changed to visible, and then it appers. I would like to keep the content visible without having to press the handle, like in the imagem below:
I downloaded the SlidingDrawer source code from http://blog.sephiroth.it/2011/03/29/widget-slidingdrawer-top-to-bottom/ in order to try to change the code and get the expected result, but I am not getting.
The XML for the sliding drawer:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<br.com.dina.partial.example.MultiDirectionSlidingDrawer
xmlns:my="http://schemas.android.com/apk/res/br.com.dina.partial.example"
android:id="#+id/map_slider"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
my:handle="#+id/Handle"
my:content="#+id/ViewLayout"
my:direction="rightToLeft"
my:bottomOffset="-65dip"
android:layout_below="#+id/test">
<Button android:id="#+id/Handle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="handle"/>
<LinearLayout android:id="#+id/ViewLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.markupartist.android.widget.ActionBar
android:id="#+id/actionbar"
style="#style/ActionBar"/>
<FrameLayout android:id="#+id/ViewContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white" />
</LinearLayout>
</br.com.dina.partial.example.MultiDirectionSlidingDrawer>
</RelativeLayout>
Is there a way to achieve what I want?
Many thanks
edited to add the xml
Use the onDrawerScrollListener, onDrawerOpenListener, and onDrawerCloseListener to change the visibility of certain items depending on the state of the drawer. So when you say "the drawer is closed...and the content view is invisible" then in your onDrawerCloseListener set the content view to VISIBLE. Give this a try and let me know how it goes.
EDIT so you did something like this?:
drawer.setOnDrawerCloseListener(new OnDrawerCloseListener(){
#Override
public void onDrawerClosed() {
//get the ViewContent by id and set visibility to VISIBLE
});

Resources