Is is possible to put fixed buttons (with image) on top of an android map.
I want to add buttons on top of the android map then when the user click on it, it performs something on the map.
Similar to the zoom control, but always visible.
Put the map and the button in a relative layout. Something like:
<RelativeLayout>
<MapView>
...
</MapView>
<Button>
..make its align parent top property true here
</Button>
</RelativeLayout>
This should put the botton on top of the map and aligned to the top of the screen. And if you want to have a button with an image use ImageButton insead.
You're referring to depth or z-indexing when you're saying "on top of". Use FrameLayout and set MapView first then followed by Button.
<FrameLayout>
<MapView />
<Button .../>
</FrameLayout>
Edit I mentioned gravity which was wrong.
Related question: Placing/Overlapping(z-index) a view above another view in android
Related
I am developing an app on Android with this form :
<ScrollView>
<RelativeLayout>
<TextView/>
<RelativeLayout>
....
</RelativeLayout>
<gridLayout>
7 CheckBoxes
1 ImageButton
</gridLayout>
<LinearLayout>
many TextViews
</LinearLayout>
</RelativeLayout>
</ScrollView>
The ImageButton inside the gridLayout controls when some of the checkBoxes disappear (VISIBILITY->GONE) and when it's pressed (the ImageButton) the LinearLayout, which is just below it (the gridLayout), overlaps the gridLayout before it takes its final form. See the images below :
[1]: https://i.stack.imgur.com/K6aSc.png This is before the disappearance.
[2]: https://i.stack.imgur.com/nHqpj.png This happens during the disappearance.
EDIT: The problem happens because the View.GONEtakes some time to be performed visually, but the gridLayoutunderstands that it happens immediately, so it reserves the "empty" space right away. Only think I can figure out, is to set the View.INVISIBLE instead and resize the gridLayout manually. Is there a better way?
EDIT2 The problem is caused by animateLayoutChanges="true". Due to the animations, it take some time for the checkBoxes to disappear. Is there a way to force the linearLayout to "wait" for the effect of the animation to end?
Any ideas?
You can add a listener to your animation changes of animateLayoutChanges="true" and move the LinearLayout when the animation ends. More information in this thread - Listner
Also, you can try a combination of setAlpha(0) and setEnabled(false) on your checkboxes in which case gridLayout won't adjust the views again.
I use a Mapbox map in a scrollview. In this scrollview I have the main LinearLayout and inside this, I have 5 areas with different information. The Map is in the third area.
Due to the amount of data in the first and second area, while displaying, the Map area must not be visible and to see it, you'll need to scroll.
Unfortunatly, the Mapbox seems to have an "automatic center" sistem: as soon as the Scrollview start to be displayed, it's position is set automaticly to the center of the Map.
So the user has to scroll back to the top of the scrollview.
How to avoid this "initial position feature"?
Note: this is NOT a duplicate question from this: Using mapbox in scrollview, scrollview sliding to the position where mapbox is put in the page
as the problem is NOT "how to move the map and don't move the scrollview". The problem is the initial position of the scrollview. Also the answer "do mScrollView.scrollTo(0,0);" is NOT acceptable as with that, the scrollview is first centered to the map and AFTER, there is a scroll.
Edit: here are two pictures and more details.
This first snap show the scrollview in vertical mode. I've a first area named "INFORMAÇOES" a second one named "TIPO DE OCORENÇA", a third with the map and after than I have 2 others area.
Due to the size of area 1 and 2, in vertical mode, the map area is partially visible. This snap show the screen at start of display.
This second snap is taken at the same time so at start of display, but in horizontal mode. Of course, the amount of visible data is different. What we can see is that the map area seem to force a scroll in order to be displayed.
After making some test I discovered strange thinks: when you scroll, you commonly set the top of data at top of screen. In the case of the map it's not the case. The first element which appear quickly at start of the display is the Mapbox logo.
Here is the XML part:
<LinearLayout
android:layout_margin="5dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_below="#id/linearLayout_type"
android:id="#+id/linearLayout_map">
<com.mapbox.mapboxsdk.maps.MapView
mapbox:zoom="12"
android:id="#+id/mapview_inter"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
The tests I've made:
1 - put a android:visibility="gone" in com.mapbox.mapboxsdk.maps.MapView. it's not allowed.
2 - put a android:visibility="invisible" in com.mapbox.mapboxsdk.maps.MapView. it's not allowed.
3 - put a android:visibility="invisible" in the linearlayout of the map (linearLayout). Change nothing. The map is not visible but the "scroll" happened.
4 - put a android:visibility="gone" in the linearlayout of the map (linearLayout). In that case, that's OK: the "INFORMAÇOES"part of the data is at top. But their is no rendering of the map. So when I perform a
LinearLayout tmp = (LinearLayout) findViewById(R.id.linearLayout_map);
tmp.setVisibility(View.VISIBLE);
to see the map, I see... nothing :(
Any suggestions?
First, you should give a either your LinearLayout a specific dp size or the MapView. Right now you are using match_parent for both. You can force the ScrollView to the top by using scrollView.fullScroll(ScrollView.FOCUS_UP); inside the OnMapReady callback which fixed the issue for me.
I need to do a Sliding Up View wich should slide up from the bottom of the screen when I click a button. It has to show on the bottom of the screen and I need to slide/drag it to the center of the screen. The images below explain it better.
almost like the AndroidSlidingUpPanel from "umano" which you can find here:
The problem is that I want the first child (The content of my View - an image for example) to fill all the screen and also I want the second child(the actual bottom bar) to be showed when I click a button. The images below explain it better. If there is not possible to do this by changing the AndroidSlidingUpPanel, how can I do that? I have never worked with views like this. I would really appreciate any tip or help. Thank you very much.
To hide or show panel, you can use
showPanel()
method.
To hide it try this:
SlidingUpPanelLayout slidingPanel = (SlidingUpPanelLayout) findViewById(R.id.sliding_panel);
slidingPanel.hidePanel();
To make it appe
SlidingUpPanelLayout slidingPanel = (SlidingUpPanelLayout) findViewById(R.id.sliding_panel);
slidingPanel.showPanel();
This is available only in v 2.0 of AndroidSlidingUpPanel (https://github.com/umano/AndroidSlidingUpPanel). As I know, it's included in android support library v13 now, but not sure if there is latest version.
You can check this library for dragging content from all four edges of the screen https://github.com/SimonVT/android-menudrawer
You can make a custom layout inside this menu drawer to get your expected result.
You can do it with AndroidSlidingUpPanel, just set visibility:
android:visibility="GONE"
on the 2° child of the view (the panel) and use .showPane() and .hidePane() on SlidingUpPanelLayout to show/hide the panel when you click the button.
The following library do it as well
https://github.com/Paroca72/sc-widgets
Inside you will find a widget named ScSlidingPanel.
This widget work different from the other and can be use and customize very easily.
You put it inside a RelativeLayout give an alignment and it will open from that side.. Left, Right, Top and Bottom or mixed..
In your specific case your must align your panel at bottom of the container and it will sliding from the bottom.
<!-- Define the container -->
<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"
tools:context=".MainActivity">
<!-- Sliding from top -->
<scapps.com.library.ScSlidingPanel
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<!-- HERE THE YOUR CONTENT -->
<!-- or you can load by setLayout method -->
</scapps.com.library.ScSlidingPanel>
</RelativeLayout>
Another important property that you can use right for your case is the handle size.
You can define an handle and define the beavior of it.. as your image above you used a button.. you can unsing an image and setting setToggleOnTouch() to true for open/close the panel touching on handle.
I'm trying out the Finger Paint api demo and I'm trying to add buttons to it. I have included
<view class="com.triopsys.imosandroid.ViewControllers.SignatureViewController$MyView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
In my layout xml, but I can't add buttons on the top or bottom of this view.
You can't add buttons to a view... You need a view group ... Linear Layout/Relative Layout.... Rather than trying to do the markup yourself use the visual editor and add two buttons and then take a look at the xml it should point you in the right direction
I am attempting to draw the medal overlaying the corner of the score screen shown here
There is an transparent layout holding the buttons and a RelativeLayout (black edge box), which holds the interior box (grey box) that contains the rest of the data. I tried adding the medal to the top left corner of the interior RelativeLayout and giving it negative margins, but that just cuts it off at the edge of the view. Adding it to the transparent layout puts it behind the corner.
How can I force the medal to overlay that corner? I'd prefer to do it in xml if possible, but any suggestions are welcome.
You can also achieve this by setting the android:clipChildren="false" and android:clipToPadding="false" attributes on the parent view (and if that doesn't work, set it on all the ancestor view groups as well, eventually it will work).
In the xml layout, an element that define after will overlay the element that define before.
So, you could change layout to something like this:
<LinearLayout>
<LinearLayout> <!--grey box --> </LinearLayout>
<ImageView src="medal" android:layout_marginLeft="-250dip"/>
<!-- change the amount of marginLeft to your desire -->
</LinearLayout>
merge them ...
http://developer.android.com/resources/articles/layout-tricks-merge.html would help