Add custom Views to a View without extending layout? - android

I have a class that extends View and allows me to plot data. I want to make another class that extends View that contains two of these plotting views. In my particular case, I am unable to extend a layout such as LinearLayout and add views to it. My parent class has to extend View. Is it possible to build a View that consists of other custom Views without extending a layout?

Here's your answer. You can create a Custom Compound View.
http://code.tutsplus.com/tutorials/creating-compound-views-on-android--cms-22889

Related

setContentView as a Class That Extends SurfaceView

I need to set my content view as a class that extends SurfaceView but when I do so, I can't access the ImageViews, TextViews, etc. defined in my main.xml file. If I tried getting an ImageView for example, it'll be null. So how can I have the elements defined in my main.xml layout in my SurfaceView class?
SurfaceView is a View not a ViewGroup. This means you cannot have children for it in traditional way. You need to draw the children yourself.
This example gives you more details on how to use SurfaceView: http://www.edu4java.com/en/androidgame/androidgame2.html

Android Add UI Elements to a CustomView class

I have created a CustomView class, a class that extends View.
In this view I would like to be able to add UI elements like a Linear Layout with Buttons, TextViews etc.
How should I do this in the most efficient way?

How can I add a layout to my customized view

I have a class that extends view and in it I am creating my customized view. At certain step I want add a layout created here in tis question to my customized view.
I also referred to some examples but but they seem have the same problem reversed, they have a layout and want to add a customized layout to it.
How can I add a layout to my customized view?
Maybe your class should extends ViewGroup instead of View.
With a ViewGroup you will be able to use addView() to add inflated layout in your custom view.
For more info on addView take a look at Android doc

How to a add button to view

I am developing a game, and I have a class that extended View(Not a xml file).
I want to add Button to my custom view, But my extended view has not addView method.
How can I do this?
Your class has to extend ViewGroup, not View.
If you want to keep your class extend View you have the possibility to create an object which extends the ViewGroup (for example: LinearLayout, RelativeLayout...). Then put your costum view and the button into this ViewGroup.

Is it possible to place an imageView in a class that extends View?

Is it possible to place an imageView in a class that extends View in android?
If possible please give me a sample code.
Thanks.
If you want to create a custom view that contains an ImageView (and presumably some other items), you probably just want to extend a ViewGroup, such as a RelativeLayout rather than directly extending View.
See the "Compound Controls" section of the Custom Components page on the Android Developers' site.

Categories

Resources