I have a ListView with my own adapter, who uses a own layout.
It's basically a horizontal LinearLayout with an Image and a TextView
I have specified a selector for my ListView, which changes the background color.
Furthermore I want to apply a ImageColorFilter on the ImageView. If the background changes.
Is there a simple way to do it with the build in ListView selector behavior or must I attach my own OnTouchListener to my LinearLayout?
I guess there are two possibilities:
Disbale the ListView selector and write your own OnTouchListener and
handle the touch events.
Use android:drawSelectorOnTop="true" to draw the selector on top of your View instead of drawing in the background.
Related
The problem
Suppose you have a view inside a layout view, and you wish that each touching event on the layout would affect the view's background selector.
for example, when you touch the layout , the selector of the view will choose the state_pressed state.
What I've tried
I've read about duplicateParentState and addStatesFromChildren , but I think it's the opposite of what I'm searching for.
I've also tried to use splitMotionEvents, but it didn't help.
The question
How do you do this?
Also, what should be done in case the layout is inside a listView (as an item within it) ?
Consider you have a spinner inside a linear layout. Make focusable property of view(here that is spinner) to false. And onClick of linear layout call performClick on view(spinner in this case).
EDIT:
In focus Change Listener of linear layout if it has focus, call requestFocus on view.
You can follow same method to other states of view
Another method:
do not apply any selector to layout(linearlayout in this case) and add whatever selector you want to view(spinner in this case). For view add this parameter
android:duplicateParentState="true"
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.
I Have a GrinView with costum Adapter that defines some ImageViews and set onClick event. When the user clicks the buttons it show some orange background, as the iimage bellow. How can I avoid this background display?
Try setting
android:background="#null"
in your layout xml.
Are you sure you are using a ImageView with onClickListener? If you are using an ImageButton, try changing it into a ImageView (that doesn't bring onClick-animation).
Cheers
I am trying to highlight touched cells of my listView. Because the cells have a backgroundimage set I use an onTouchListener for the View of the tableCell to change the ColorFilter.
As described here the onTouch Listener seems to conflict with a OnItemClickListener of a ListView.
So is there any easier way to highlight a cell with a backgroundimage?
You can setup a list selector property and a drawable file for the state_selected/pressed etc.
I figured out that StateListDrawables can also be created programatically, so I could use a generic approach for setting background pictures.
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.