Android : drawing on activity with other views - android

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

Related

Android: How to manage multiples Views without XML

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.

Android: Show custom UI View in Eclipse layout viewer

Does anyone know how I can get my custom view object to appear in Eclipse's Android layout tool when I put the parameters in my layout file?
If you don't want to put any code here, just a link to a resource would be great too. I'm not having any luck searching for what I want.
Thanks.
Having your view displayed in the Layout View in Eclipse is not straight forward. From what I've seen (it's not exhaustive at all), using a completely custom View / Surface View with the rendering placed in a separete thread does not work.
But if you're building a custom View based on an existing one (for example inheriting from an EditTExt) and only overriding the onDraw method, then the layout manager will display your view as intended. The the parameters inherited from the Android View (here EditText) will apply to your custom View. Custom parameters won't have effects (I think).

Android: Control Hierarchy in Custom Components

I'm reading the android docs on custom component development and i'm a little confused. If you're creating an activity, you can add add a hierarchy of views via setContent. however, if you're creating a custom component, you have to handle everything in the draw() overload.
if i want to build a custom component that relies on a view hierarchy, is the model simply to create a hierarchy internally and then in draw call myViewHierarchy.Draw() or something?
however, if you're creating a custom component, you have to handle everything in the draw() overload.
Not necessarily. That's one approach, but hardly the only one.
if i want to build a custom component that relies on a view hierarchy, is the model simply to create a hierarchy internally and then in draw call myViewHierarchy.Draw() or something?
No. Just add children to a container, then add logic to the container for representing the composite widget. For example, I have a ColorMixer custom component that combines three SeekBars, three TextViews (labels for the SeekBars), and a plain View (used to provide a color swatch).

Android ImageView draw

i have the following problem.
I am working with a library of maps which paints the icons on the map using drawables and canvas.
Now, i'm trying to modify it in order to the user can click on icons. So i want to attach drawables into different ImageView with a onClickListener.
However, i don't know how i can paint the ImageView using canvas from method onDraw.
I've tried with:
ImageView iv = new ImageView(context);
iv.setDrawableResource(drawable);
iv.draw(c)
But it doesn't appears in screen.
Any idea? Thanks
You might have better luck if you provided more context -- what's "c" represent here? But in any case, you can't just create new imageviews, you need to attach them to your layout, either by inflating them with a parent view argument from XML, or calling your parent layout's addView() programatically.
Generally, you'll rarely call any draw() methods by hand (unless you're implementing a custom view of some sort); you'll inflate your views from XML into your layout, or else instantiate your views, set whatever LayoutParams you need, and add them to a layout. The Android UI libraries handle figuring out when standard views are invalidated and need to be redrawn, for performance reasons and your own sanity.

android custom view how to draw button on top of the view

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

Categories

Resources