I have a class like that, and there are about 10 of them
public class DataItemPlainView extends View{
public DataItemPlainView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}}
Now I need to put TextView, ImageView etc inside this view. And when I call it from somewhere, I want to get my customView. setting a view to a custom layout is a case too.
Thanks
Creating custom views. By extending the View class or one of its subclasses you can create your custom view. For drawing view use the onDraw() method. In this method you receive a Canvas object which allows you to perform drawing operations on it, e.g. draw lines, circle, text or bitmaps.
A well-designed custom view is much like any other well-designed class. It encapsulates a specific set of functionality with an easy to use interface, it uses CPU and memory efficiently, and so on. In addition to being a well-designed class, though, a custom view should: Conform to Android standards.
Custom view are useful for some cases: create something non-trivial visually speaking - meaning you want to draw something yourself to the screen, for instance- graph.
ViewGroup is a collection of Views(TextView, EditText, ListView, etc..), somewhat like a container. A View object is a component of the user interface (UI) like a button or a text box, and it's also called a widget.
Your custom view needs to extend ViewGroup
or one of the other classes that extends ViewGroup
. For example, you could extend from RelativeLayout
or LinearLayout
if those layouts fits what your custom view needs to do.
Remember, even the layout classes are just another View
. They just happen to have methods to add other views as children and have code to recursively measure and draw their children.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With