Context:
I've managed to create a custom BaseAdapter for my ListView which renders my elements correctly. I've got a nice 4x4 grid of items beautifully drawn.
Now I'd like to change the state of one of the items on pressed (like a button OnPressed state). I've achieved this with a custom control derived from button, and some custom states. This allows me to programatically or on touch, change the state of the item in question. Perfect.
Problem:
Now I'd like the elements (in a given state) to exceed the bounds provided by the listView. The adapter's getView method returns a view, but this (AFAIK) fits within the columns provided, with the listview expanding to fit the view returned. What I want is to specify the height of each row, but allow the item to fill beyond these bounds. For example, on press I'd like to draw a big circle around the item touched - this circle would overlap other elements as it encompasses the item; the circle exceeds the bounds of the element it encircles.
Is there a simple padding or layout parameter to specify allowing the Drawable to exceed the bounds of the space allocated by the list view? Or do I need another view of a circle ontop of the ListView and position at the right place on touch? (the circle is currently a background drawable of the button, shown via a selector for the correct state).
Related
I have a list view in my app with elements where an image covers pretty much all of the view. There was an article by google where they explain that selectors should be drawn on top of the item if the item's background is not visible or else you wont see the selection highlight. Can't find this article anymore.
The list view has been correctly configured with drawSelectorOnTop and a selector for various states. Each item on a list view is a RelativeLayout with a background selector for various states including activated. When selecting multiple items and marking them as checked, the items are correctly marked but since a big image covers almost all of the view, just a fraction of the background is shown in the highlighted color.
I fixed my problem by wrapping the relative layout into a frame layout and setting a foreground drawable to draw the highlights. It works, but I don't like adding the extra layout on my elements.
Ideally, the selector of the listview should be used to mark the items, but apparently not. I included all possible states on the list view selector but it never leaves the item highlighted.
My question is: is wrapping items in a framelayout the correct way of doing this or is there a better approach?
How to create this below view.
1)using listview or
2)inflating custom view in scrollview.
This is not only problem.
If list view then how to overlap the rows.
Each row have different color and that will come from api webservice.
In listview, at each row i have problem with red part which i have marked in second image.
even each row background is different and that same color will appear in below row.
How to do texture effect in listview?
The issue breaks to many things:
How to draw overlapping views?
I would try setting negative values for vertical paddings, but it's a wild guess. Also, you can just divide the graphics and draw views as rectangles containing view N and some parts of the N+1th view.
What about non-rectangular hit area?
You can manually detect clicks using color picking, shapes, or just simplify the view's clickable area to a rectangle.
What about visibility detection?
ListView shows only views, which are visible. I'm not sure, but most likely it won't work with negative paddings or similar hacks.
Personally I would write a custom view with ListView-like adapter and dynamic row loading.
I have try a many ways, and the best and fastest is simple set negative divider to listview like so:
android:dividerHeight="-100dp"
I want to have ListView with some customized (layout) items. Background for those item has transparency on its bottom side. I want next item (after this customized) to be positioned a little bit top (something like minus margin in CSS). If in LinearLayout of list item (this special list item) I can do android:layout_marginTop with minus values? It seems to doesn't work, so what is the better solution? I need to little positioning next list item.
I don't think that the listView exposes this functionality. As an image trick, however, if you can modify the images, just put the transparent section (I assume it's a shadow?) on the top of your listItem background image so that it LOOKS like the item above casts a shadow, but in reality the shadow is part of the background of your listItem
I have recently encountered a very specific issue/requirement regarding an Android Button and ListView item. The requirement is something like this:
we need a button that can display a glow/aura of a specific dimension and opacity when clicked, however this glow/aura must not be part of the button itself and needs to be displayed over the neighbouring views.
same requirement for list view items - they need to glow over their neighbouring items and the list view margin.
Any idea/suggestion would be highly appreciated.
Thanks.
A solution could be in drawing a round rectangle with stroke around the button. You can get the button position using View getTop(), getLeft(), getRight() and getBottom() methods.
The round rectangle could be a custom view that has the onDraw() method overridden. You can also have a paint attribute, in this view, if you what to add the gradient and opacity, to look more like an aura. When you first create the view it should be invisible or transparent and only on demand it should appear.
From your main activity you have to add this new view, by using the layout.addView() method and depending on your demands you can make it visible and/or change their properties.
An example can be found here: https://github.com/codesorcerers/auraview
Hope this helps!
Bogdan Popa
I've got listview that in a row it contain 3elements: imageview, textvie and another imageview. I've set my listview to setItemsCanFocus(true) and every item is set setFocusable(false). Screen:
http://img252.imageshack.us/img252/4042/zrzutekranue.png
I can navigate on the screen (click on text/image, I have those fields set to clickable and focusable), but there is no visible focus. I'd like to have the default focus style, when background changes.
I can add sth like:
setBackgroundColor(xxx)
but I'd like to have that fancy background that is lighter in the middle and darker at the ends.
The upper row on the pic is what I've got, and lower is the ideal focus notification, of course it should be narrow so it would only be background of the text view.
Sorry for my English.
PS I also used for textview
android:layout_height="fill_parent"
to fill for height which isn't the best piece of coding.
In the List View, all the list items are in different views. In your case the Image View, Text View And Image View lies within a single View. So according to me you cannot have focus on the items within a single View in a list View.