Is it possible to add a button to a class that extends View? ""public class josh extends View "" If not how can I merge a button onto the view when it is referenced in my main activity? uhg please help....
Two ways:
Have both the button and your custom view as children of a FrameLayout, by which the button can be drawn over your custom view.
Don't have a real button. Instead, draw something that looks like a button, treat touch events specially if they're within its dimensions, etc. This is more appropriate for something like a game.
I believe you can do #2 but have a subclass of Button do the drawing, so that it performs exactly like a normal button and is just positioned/sized by your custom view, but I don't know how to do this.
If are wanting to add a button to a view at runtime check this preivoius question... How to add a button control to an android xml view at runtime?
Related
I want to add three textViews in a single button.
I can do it using linearLayout as an XML file and then inflating it to my custom button class but somehow when I set click listener on this type of custom button it won't work.
I desire for a much better option, maybe extending the Android button class and then change it according to my requirement, but unable to inflate my button to my desired views.
Please assist me on how to do this.
Creating LinearLayout and setting style="#android:style/Widget.Button"
Did the trick for me.
You can design your layout with the three textviews as usual. For emulating click, set a StateListDrawable as the background of the root container. Put this in any layout (or use <include>) and attach a clickListener as usual.
You can simply use LinearLayout with 3 textview as its child and set click listener on it. No need to create custom button class. But I do not know exact requirement so need more details for creating custom button class.
In my application I need to have something like image below. I have experience of creating custom components and I know how to do it. However, I have no idea how to create this kind of component. Do I need to do something like when we are designing custom rating bar?
Anyway, their so many way you can achieve this.
One way i am seeing using radio group and radio button, vertical lines and text view you can easily achieve this. Put everything inside a layout of your choice and then just inflate the layout where ever you need. After that you just need to set the radio button like this radio1.setChecked(true).This is a simple solution but may not a be a optimal one.
Alternatively you can create a custom view by extending view class or any of its subclass, whatever you feel suitable for your work then override its onDraw method do the entire thing manually.
Im writing an app. I create my own class that extends View, then setContentView(new MyView());. Sometimes I want to draw popup with options. Now I draw it with shapes. I was wonder is there a way to make another View or View-like-class and use it as popup?
Another question: Can I use EditText in my own View, also without XML?
Yes, you can use addView method and put new EditText, but be sure about layout params.
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().
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