the effect I want to achieve:
normal:
pressed:
notice the imageview is masked too when pressed, so apparently setting the layout background to a selector xml will not solve the problem
thanks in advance!
Use a semi-transparent selector (e.g. a color with alpha) and set android:drawSelectorOnTop="true" in your ListView. The list will draw selector above and you will achieve effect you need.
Simple,
Let your child parent be a FrameLayout
one child will be your current view, other will be an empty view with attribute match_parent, match_parent with background and alpha required in your picture
Initially it will be hidden, on press child just make this view visible and vice versa.
Hope it help.
Related
I have a widget with a button, an image and a title and a black background (linear layout). These views are separately clickable. But how to treat all as a single item? (like androids default power widget has an icon and a green bar at bottom but acts as a whole and an orange border is shown on press). i need on click whole widget area is lit and again on click whole widget area is greyed. e.g an invisible button covering the whole widget area is also ok. thanks for your help in advance.
For the child views you need: android:clickable="false" and android:duplicateParentState="true". This causes the child views to not be clickable and to also take on the parent view's state (e.g., pressed). For the parent view you need to set android:clickable="true". To make it clickable. Then you only handle the onClick event from the parent view.
Views, just like buttons, have the setOnClickListener() method. By setting android:clickable="true" in the XML, you can handle the onClick the same as you would handle it for any other object.
Currently, I have an Activity, with a ListView on the top, and LinearLayout on the bottom.
When a row in my ListView is scrolled and the row is partially shown, it looks like this. (LinearLayout is the one with Value wording)
However, I wish to have the following effect.
It seems that LinearLayout adds a "glooming layer" at the bottom of the ListView. - I am sure this is not optical illusion. :)
How I can achieve such an effect?
Add
android:requiresFadingEdge="vertical"
on ListView will solve the problem
One of the ideas that comes in my mind right now is to create a shape with a transparent gradient color. Then create a View above the LinearLayout and put the Shape as the background.
Another idea is to put a transparent image, instead of shape, above LinearLayout.
I am getting a orange highlight color in the GridView, when i press it. As I have specified the padding, this highlight appears in that area.
Can somebody please help me to know, how to avoid it?
I have used OnKeyDown event for the GridView, but call does not comes to that. As such the adapter provides images for the region which is left without the padding.
Wanted to add a non-link answer:
In the xml for the gridView, add the following attribute
android:listSelector="#android:color/transparent"
That will make the selected state color of the gridView transparent, and will, in effect remove the orange highlighting.
I hope, my issue would be clear for you from my question title. I have three linear layouts in each row of the list view. One linear layout contains an Imageview and the other two linear layout contains text views. These three linear layouts comprise my list view row. But, to my surprise, the listview default selection(orange colored) does not work when I move the trackball of mouse or when I select it from the phone.
Can anyone guide me resolve this issue.
Any help is appreciated.
Looking forward..
By default, the list selector is drawn behind the currently selected item. If your item layout has an opaque background, the selector cannot be seen.
Try making your list item background transparent.
Did you add a background color to your row's layouts? If so, that color will be the only color you see - even on touch events.
A row's background should really be set to a selectable drawable with different colors for different states like selected and unselected.
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.