Floating Buttons over a screen filling view? - android

I´m having a problem with my Android Project.
I have a screen filling custom View, which displays a canvas. The canvas consists of a background picture and another picture layer, in which can be finger drawn. Additionally, the canvas view can be dragged and pinch-zoomed.
Now I implemented a detection for 'longClicks', i.e. finger down on same region for 1 second. As a result of this gesture, a small menu should pop up over the pointed region. The menu itself should consist of something like a TabHost/TabWidget, i.e. smaller icons on riders on top which reveal separate EditText, Buttons etc. at the lower part of the menu.
Now the question is: How can it technically be done?
1) I played around with TabHost etc., but I think it´s only possible to use when having a TabActivity. Is this correct?
2) Then I searched for a possibility to overlay my main activity with this TabActivity, resulting in that it´s possible, but I couldn´t really control where the overlay Activity was placed, it always started on top left. Is there a possibility to place an Activity somewhere on the screen?
3) Next I discarded my idea with the tabbed menu and searched for a possibility to only overlay my view with another view (and have the possibility to remove it later again). I read, that it´s possible with the ViewManager. But how do I access the ViewManager? Documentation says: http://developer.android.com/reference/android/view/ViewManager.html
call Context.getSystemService().
but via this function, I can only get the WindowManager and not the ViewManager. wtf?
I´m really stuck right now...can somebody give me a hand here?
edit:
I managed the view over view problem by programmatically instanciating a Layout and then handing it in as contentView.
rl = new RelativeLayout(getBaseContext());
rl.addView(cview);
cview.setId(1111);
View overlay = getLayoutInflater().inflate(R.layout.menuoverlay, rl, false);
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_LEFT, cview.getId());
lp.addRule(RelativeLayout.CENTER_VERTICAL, cview.getId());
rl.addView(overlay, lp);
Now when making the Layout static and by writing some getter/setter methods, I'm now able to control adding and removing of views.
private static rl;
//scroll scroll
public static void addView(View view){
rl.addView(view);
}

1) I played around with TabHost etc., but I think it´s only possible to use when having a TabActivity. Is this correct?
No. For an example of using TabHost without a TabActivity, take a look at Is it realizable on Android?

I finally used PopupWindow now.
http://developer.android.com/reference/android/widget/PopupWindow.html

Related

Putting a button on top of an imageView

So here is my problem. I've spent couple of days on this and didn't get anywhere. I've tried every layout possible, but it just doesn't seem to work.
Basically, I have a map of a floor and I want to make it so when you click on different parts of that floor, a new activity or a dialog box shows up. I want this to scale for all the devices. Why is this so difficult in Android? I would think that putting buttons on top of an image would be easy and made sure that it wouldn't move like in HTML.
I have been looking into Surface View, but wasn't sure if that's the best way to go? I can get the coordinates of the objects on the floor, would that help?
I want to implement this inside of an fragment. Thanks!
One possible solution could be to have a RelativeLayout as the base layout of your 'Floor Map' fragment, with the floor image set as its background.
Then you could add buttons or any other views to the Relativelayout at the coordinates of the objects.
If you already know how many features the floor will have, you could add the buttons statically, otherwise, loop through your array of features to add them dynamically.

How do I make a section of an activity always-on-top?

Had a question about making part of a View Always-On-Top. Please see the Groupon picture below. The black window at the bottom where it says "From $29" & "Buy!" is always on top of the activity page. Meaning the rest of the page is scrollable above that black window at the bottom. Please note I only want this activity to have an Always-On-Top
How do I make a portion of the activity Always On Top? And what kind of layout did you think they used for Groupon? I was just going to make a RelativeLayout and layout_alignParentBottom="true".
You could probably get away with having a vertical linear layout with two children. The first one a scrollable area and the bottom a view with whatever it is you want to be 'on top'. Since there's no transparency there's no visual difference between having the black view as always-on-top and having one view on top of the other (in the y-axis, not z-axis). Plus, if you do it this way you can reach and see the bottom of the scrollable view's content.
To the best of my knowledge, the best way to do this is by implementing a BaseActivity with this View, and have all your activities extend this activity instead of the standard Activity.

Freely move imageview around page

i'm using Eclipse to make an android app. I'm a beginner and i'm wondering how on earth I can place an image on my page where ever I want. It keeps locking in certain places due to alignments. Surely you must be able to click the image view and drag it into the desired place??
thanks
If you use RelativeLayout or FrameLayout as a container, you can place the inner Views wherever you want. They still have to be aligned somehow, but by changing the margins they can be on every position in the parent.

Slide navigation menu from bottom

I'm trying to implement a sliding menu, like in Prixing app. (The menu which lays under main layout and get visible when you take and drag main layout to the side)
But the trick is - i want it to appear on bottom of the screen, so I need to move the main layout to the top.
The second problem is that in tah layout I got a listview.
Please, I really need advices or maybe link to some usefull resources where I can understand how touch events are handled.
Thx!
i think you are try to do same as facebook app. i have found demo for it. so use this
there's really no magic on it.
To make it, move directly (in a button click or something):
you use a animation to change the LayoutParams.top from both fragments (the one on top (currently in view, and the one on the bottom, hidden under the screen).
On your XML layout make sure to set a fixed height for the bottom layout (in DIP) and during runtime animate the two layouts to move that amount of pixels.
To make it move with the user finger:
That will be tricky, because the listview MUST receive the the user input. Maybe if you call super on it.
But you can accomplish it by receiving OnTouchEvents:
TOUCH_DOWN, you start the move (mark it with a boolean or something)
TOUCH_MOVE, you apply the same change to the layout params that you did on the animation (1st option)
TOUCH_UP or TOUCH_CANCEL, you stop the move (clear the flag).
hope it helps pointing you to the right direction.

android custom view how to draw button on top of the view

I am creating a android app using LunarLander as a example.
Now I need to create a few buttons which are drawn over the view.
I do not want them as a seperate layout above or below the view but in the custom view.
Is this possible or am I going to have to programmatically show the button images then detect the touch. The buttons I create using new never show on the app. I assume this is because I have overwritten the onDraw and the buttons are never drawn even though I call
super.onDraw(canvas);
I think you could use FrameLayout to show two layers - first would be your surface from lunar, and second is the layout with buttons etc. You could define everything in layout.xml file. Probably that is enough.
Regards!
If your view extends Linear/Relative/TableLayout, you can use view.bringChildToFront(child).
Use AbsoluteLayout & then in your ui thread set button.bringTioFront() & you are done!
watch this post Problem when using more elements in the ListView

Categories

Resources