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
Related
I have a layout, but I need put more views (Buttons, EditText, etc), but how you know, the layout of the ADT is a bit small and I can't to set more views or know where is it, Somebody know How can I set more of these?
Thank you
Android isn't like iOS how you can just position elements with drag & drop.
RelativeLayout will position elements relative to each other and LinearLayout will lay out elements sequentially in a linear fashion, either vertically or horizontally. Both methods are better executed by actually writing the View XML yourself.
I suggest reading this: http://developer.android.com/guide/topics/ui/declaring-layout.html
If you want to actually see what you are adding to your layout without messing with the XML you could maybe change the device that the renderer is using to preview your layout.
I don't know what IDE you're using but in Eclipse and Android Studio you can change the device that your layout preview is rendered on. That way you can see what you're adding as you add it.
Then just make sure to put everything in a scroll view so users can access all the views and widgets you've put in that layout for your activity or fragment or dialog or whatever else it is.
I am new to android and trying to make something like the fingerlock security system of the android. The problem is that I have found a lot of reference on drawing onto a plain background (that sets different content view and allows drawing onto that), but not regarding drawing onto the same activity layout.
To draw manually on a View, you need to override its onDraw method. For this you need a custom View (often extending from an existing View type).
If you are using an xml to set the Activity's layout in setContentView() then you need to add the above custom view to this xml. Then, you can draw onto the same activity layout.
setContentView is noting but the activity view. once the view is set in main activity (max in oncreate method) it can update from multiple classes according to your logics.. i think before trying this you have to understand the view and its hierarchic properties properly
I have already created a circle with the use of a View and have not used SurfaceView at all. I want to create buttons which when clicked on show images from the drawables. But I have read on the net that a SurfaceView is required to allow UI elements to be placed on top. Is this true, can someone please help me, as I am confused on this.
Thanks.
It's not very clear what you want to do, but if you want to place UI elements on top of each other without using SurfaceView you can you a RelativeLayout, this layout allows you to have views on top of each other, do you can have an ImageView with a drawable appearing over a button for example.
If you just want to change the background/src images of a button when clicked (for example to create a 3d effect of clicking), you can check out selectors, these allows you to specify different drawables for pressed/normal states.
If you want to create buttons on a SurfaceView, I suggest you render Bitmaps that will represent buttons. You will have to programmatically check if the touch coordinates are in the bounds of that bitmap tough, to register a button click.
I hope this helps.
I am using Eclipse and a ViewFlipper. In Graphical Layout, I want to see the second, third, and forth layouts of my views - right now, I can only see the first view. Any suggestions?
If I'm understanding you correctly, you want to see each view in the 'Graphical layout' tool? The way I do this, is instead of having all the layout work done in one xml (where your viewflipper is) I make each view a new layout xml. And then have each view (xml file) included into the view flipper by using this....
<include
layout="#layout/layout_media"
android:id="#+id/flipper_media" />
Hope this helps.
just put each layout in relative layout or linear what ever you are working with then with each layout you will work with the first one in the order and etc.. then at the end put each layout in the order you want later
I had to subclass the ViewSwitcher class to display an indeterminate ProgressBar until data is ready to display in the second view. I used isInEditMode() to determine whether I was actually running the app or just previewing in AS.
You should be able to add a custom attribute to choose which child to display. This might look a bit overkill, but if you happen to already have to subclass your ViewSwitcher or ViewFlipper, i think it is not a big deal.
I will try to put an example later.
I am working on creating a custom view in android. I want to create an autohide custom view control.
This control will be holding other UI elements mostly buttons or icons. It has a small button which is mandatory, clicking which will slide the control in or out thus changing its visibility.
one should be able to add other buttons or icons to this control
The control can be placed only at the borders, which needs to be specified while creating the view.
I don't know how to start with it
Should I be extending the View class or ViewGroup class.
have a look at this
and then you have to add a dynamic layout to this drawer
I used a RelativeLayout and added a Button to the View.
When I call expandView() or collapseView(), I call mybutton.setVisibility() and let RelativeLayout know it has changed with this.requestLayout().