I have several Views in my Activity. I want to draw a Drawable over these views.
The Drawable should be on top of the views (that means it hides the views below it.
The Drawable may appear over several views (that is I can't just draw it in one view).
How can this be done?
Thank you
The FrameLayout allows you to have overlapping views. This is often used if you have some sort of background, with widgets over it.
Maybe you could use a Dialog or view with Dialog Theme with your drawable as the background?
Related
Given an activity with multiple views, is there a way to have the background dimmed while one view retains its original state (not dimmed)?
I have an existing layout with views and I am adding a dimmed framelayout over the existing layout, and would like to keep one of the child views in the existing views "lightened up" in its state while the dimmed framelayout view encompasses around it.
The way I know how to do this won't be very elegant for your particular use case. But I'll explain it in case you don't find a better solution.
Wrap your entire layout in a RelativeLayout, and then add a LinearLayout with fill_parent parameters on top of it, and a partially transparent black background. Adjust the alpha and RGB to how you see fit.
Now you can add your undimmed view to the RelativeLayout on top of the dimming. Since you're no longer inside the FrameLayout container, you'd have to adjust the positioning of this layout, and manually remove and re-add these two views for dimming and undimming, hence this is not a very elegant solution.
I have already created a circle with the use of a View and have not used SurfaceView at all. I want to create buttons which when clicked on show images from the drawables. But I have read on the net that a SurfaceView is required to allow UI elements to be placed on top. Is this true, can someone please help me, as I am confused on this.
Thanks.
It's not very clear what you want to do, but if you want to place UI elements on top of each other without using SurfaceView you can you a RelativeLayout, this layout allows you to have views on top of each other, do you can have an ImageView with a drawable appearing over a button for example.
If you just want to change the background/src images of a button when clicked (for example to create a 3d effect of clicking), you can check out selectors, these allows you to specify different drawables for pressed/normal states.
If you want to create buttons on a SurfaceView, I suggest you render Bitmaps that will represent buttons. You will have to programmatically check if the touch coordinates are in the bounds of that bitmap tough, to register a button click.
I hope this helps.
I have added a view to a layout which occupies a part of my screen. To this layout I want to add another layout which will be transparent. On this layout there should be only two lines which will scroll over the background layout. This I am doing so that my background layout is not invalidated and only the foreground is invalidated.
How can I add another layout which will be transparent?
Use FrameLayout as a parent layout and stack it up with as many layouts as you want. Thats one part of the answer. To make a layer (a layout in this case) transparent, set the alpha value in its background (a color) to 0. For instance android:background="#00777777" sets a background which is translucent with a dull gray.
You get the idea.
Use fram layout, which will allow you to add two views on each other.
I've got a ListActivity with a ListView in it. I need to draw a repeating image around the border ("on top of it (I guess after the listview is renderered))
How can I hook in my own drawing code for this?
You can use a FrameLayout to cause the ListView to overlap with a view that fills the entire screen. In this background view you could tile an image, or write your own custom View with your own drawing method.
There is no border property in ListView, as far as I know.
Instead you can put ListView into a FrameLayout and set the Background color of the FrameLayout.
Finally, set some padding to FrameLayout in order to create a border effect.
Hi
There is one way I have used, but that can be done in XML only.
android:background="#ffffff"
android:divider="#ffcccccc"
android:dividerHeight="1dip"/>
What I am doing is, putting listview in a LinearLayout. Background color of the list is different than that of layout. There is a margin set for layout. Hence the distance between list and layout will appear like a border for the listview.
Hope this helps.
I have a simple ListView and on that ListView I have placed a number of custom defined Views. The CustomView has ImageView and two TextViews.
The CustomView also has a "stateful drawable" as background, so that the background image (a 9-patch) changes if you press the Row in the ListView. When pressing the Row, the background image changes to a Red-ish thing.
The problem is that when the background changes from the default greyish, all the Views in the CustomView (ImageView and TextViews) still have their greyish background and thus creates very ugly greay boxes on top of the now redish background.
What is the best way to solve that problem? I hoped that such things were handled automatically (as it is done in for example .NET), but I was wrong it seems.
I got it =)
You can use the color "transparent"
android:background="#android:color/transparent"
Set the Views with that color, and its all good =)