Custom layout manager - android

I'm planning to build my own custom layout manager.
If there is any other way to build one apart from extending the View class, because this is the only approach I know for now and would like to know if there is any other way to do it?

LinearLayout extends the ViewGroup class
http://developer.android.com/reference/android/widget/LinearLayout.html
TableLayout extends LinearLayout
http://developer.android.com/reference/android/widget/TableLayout.html
I assume the source of both these classes are available at https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/widget/.
I would have had a look at the classes above and seen if I can extends LinearLayout or if I should extends ViewGroup.

Related

Add custom Views to a View without extending layout?

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

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

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