Putting a button on top of an imageView - android

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.

Related

Drawing a tournament bracket in android?

I have an app that will take a list of players and set them up so that you can go through and create a bracket dynamically. The number of players will change and the names as well.
Instead of showing a whole bracket, my point will be to go in columns. I.e. instead of the left side of the arrow, it show the right side:
My questions is how do I best draw this?
My initial thought is to do multiple layouts where I hard code textviews with custom drawables and lines for each column of 16/8/4/2 with just one border, but then I have to constantly change the layout setup.
My second one would be to dynamically draw it on a canvas based on this answer here, but it didn't give a lot of ideas of implementations.
My Questions: If I choose method 1, will I be able to dynamically change the layout of my activity?
If I choose method 2, how could I go about this? I'm still pretty new to android.
As for question 1, yes you can absolutely change the layout dynamically. You can create several layout files and do one of two things: The first, is you can use your activity's setContentView(int) method to completely reset the activity's layout to a new view. The second would be to identify the parent view of the bracket portion, cast it to a ViewGroup and use addView(View) and removeView(View).
As for question 2, you could go about using a canvas, but it would be quite difficult to use only a canvas, but possibly a combination of a canvas and a set of text views could work. While this isn't directly answering your question, this tutorial is one I have used in the past, and gives you an excellent sense of how to work with the Canvas class in android.

Replacing views dynamically without changing activity

I would like to know how to go about doing this small problem that I am encountering while making a video player app.
On clicking the first control(the rectangular icon) in the above image the following view must be displayed instead of it which I am quite unsure as to how to do it. Here is what it is replaced by
Also please note, by any chance the activity should not be changed. I have been able to design the views individually but having problem changing them at runtime when user clicks. Could someone go about explaining as to how it can be done or provide some suitable links to achieve my goal. Thanks.
For something as simple as this you can just change the visibility of the views.
view.setVisibility(View.INVISIBLE)
Or the more effective:
view.setVisibility(View.GONE)
Do that on the views you want gone, I suggest a wrapper class. It's either this or changing the contentView as describded below.
this.setContentView(R.layout.newLayoutToUse);
However, I have a feeling there is a better way to do what you want. It's overkill to load a complete new layout if you just want to change the image of some buttons or imageviews.
This might be a stupid solution, 'cause i'm terribly tired right now, but why not use the bringToFront() method on the View that you want to display in the front? Display them both in front of each other, maybe in a RelativeLayout, and then swap between them as you wish.
They are small objects, so don't consume memory. I don't see why this shouldn't work.
OR
Place them above one another, so they overlap and then make the above view visible/invisible depending on which one you need to display.
OR
just remembered I read somewhere that you can scroll through a ScrollView automatically from code. So display both Views in a ScrollView in succession and when pressing the button or whatever, you scroll down to make the next menu visible. When pres back, you scroll up to make the previous thing available. Should work, and might also make a nice animation between changing of the menus.

Android - What's the best way to create a Slideshow?

What is the best way to create a slideshow in Android?
Basically, what I need is to slide through a collection of LinearLayout or RelativeLayout objects, that contains inside them different views, ex: an ImageView and a TextView overlayed on that image.
On the bottom of the screen, should be some bulled points that will keep track of the currently element in the gallery.
To give an idea take a look at this jQuery implementation: http://slidesjs.com/
(I don't need the "left"/"right" controls, and the bulled points also dont need to be clickable, as in example)
Also, the slideshow should be in a cycle.
Maybe not the best, but I used a Gallery.

Drag to dynamically resize a pair of adjacent layouts on Android

I have a pair of adjacent views in an Android application. I'd like to give the user the ability to drag a widget to change the relative size of the two views within a larger container. If SlidingDrawer let the user pin the drawer wherever they wanted, that'd likely get me what I want.
My Google 'fu is failing me. I can't find a single example of this anywhere.
Thanks!
I ended up putting together a bit of code to create a custom LinearLayout subclass to do what I wanted.
The code is at https://github.com/k9mail/splitview

Right way to do scrollable view of custom buttons?

I've just started playing with Android in the last few days and have begun to put together a simple application. I am struggling to work out whether I'm doing things the "right" way or just making life difficult for myself.
The app displays a series of connected nodes on the screen, similar to a mind-map. I want to be able to tap the nodes in order to edit them. When the map of nodes becomes larger than the screen, I need to be able to scroll on both X and Y axes as needed to see the whole map. Image of current implementation at http://ubergeek.org.uk/images/nodetest.png.
Currently I don't have scrolling working, however I assume that I can do that by making the root view a ScrollView and sticking an AbsoluteLayout inside that (though it's deprecated, I wish to place objects at specific X/Y coordinates).
The nodes themselves are currently each a pair of roundrects (one for the outline and one for the fill) and a drawText and are being drawn in the main activity's onDraw(). In order to make these clickable buttons I believe I need to create a custom view for the button in order to use its onClick() events. I can then create a view object for each of my nodes and add them to the AbsoluteLayout view.
Does this sound like a reasonable way to do it in Android, or is this a horrible abuse of the API? :)
Thanks!
Nope, that sounds about right. You just need to make sure that the view contained by the ScrollView has the right dimensions so the scrollbars will show up right, but I'm sure you got that covered.
It's certainly a bit non-standard, but I'm tempted to say that your approach will work right... I'd even go so far as to say that it's not a hack. Please keep us posted on how it works out, and if anything breaks!
(Btw, the SDK mentions that you should write your own layout instead of using AbsoluteLayout. Personally, I'd say use the AbsoluteLayout.)

Categories

Resources