Backgroundcolor of ExpandableListView while scrolling - android

I have a problem with an ExpandableListView in my Android application. I've set a custom background color but while scrolling the list the color changes to black untill the scrolling has stopped. Is that normal or can you change the "onScrollColor"?

I had this kind of problem and solved it using this property in my list XML android:cacheColorHint = "#00000000"

Make sure you use a ViewHolder for reuse of your Views inside your getView Method
like in this example:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html
the background to this is that Android trys to reuse the Views while scrolling and if you dont obey the Caching Rules (eg Using a ViewHolder like in the example) you have that described problem.

Related

How to change gridview layout correctly while scrolling in android

I have a gridview in my android project which show some Items that fetch from. I use a custom adapter extends BaseAdapter and a custom layout for my gridview to show each item.
What I need is to change the gridview custom layout when a button click, I use a FloatingActionButton that when I click on that the layout change correctly, but the problem is when I am scrolling the gridview and click the FAB the gridview layout change but it render incorrectly !!!
What should I do to change layout correctly? Is there anyway to stop gridview from scrolling then change the layout?
P.S: I've used gridview.invalidate() method and some other methods like this but nothing works ! I also should mention that when the layout render incorrectly when I scroll up and down it became correct !
This should be very possible and easy using android's recycle view with it's layout manager. check up on their documentation https://developer.android.com/reference/android/support/v7/widget/RecyclerView.html

Custom selectableItemBackground

I'm using a RecyclerView for a list. I've a found a really nice solution to give the list click feedback and ripple (on Lollipop).
Basically I'm giving my row layout the attribute:
android:background="?android:attr/selectableItemBackground"
And everything is fine, except that I need a different background color for my list (default state). How can I override just the basic state background (not clicked) giving it a different color?
This will give custom background color and default grey ripple effect:
android:background="#color/YourCustomColor"
android:foreground="?android:attr/selectableItemBackground"
You can try this: it helped me a lot, this way we can use the background we want and keep the great click feedback.
Wrap your row view inside a frame layout.
Are you using CardViews in your RecyclerView? If so, programmatically use .setCardBackgroundColor() in your holder to each CardView. Alternatively, you can wrap everything in a simple dummy FrameLayout (with an android:id) in the CardView, and programmatically change that layout's background when you bind the ViewHolders.

Setting a background resource for many linearlayouts in scrollview causes lag

I am dynamically adding around 150 linearlayouts to a scrollview in a grid-like layout. If I set the background resource to a drawable for each of them using setBackgroundResource(R.drawable.x), the scrollview shows extremely noticeable lag and choppiness, even though the drawable is a simple colour and border.
If I remove the call to setBackgroundResource, the scrollview is smooth again.
Is this expected to happen with so many views containing backgrounds? If so, how would I go about making a grid with custom backgrounds for each cell?
You're going to want to use a list view in your scroll, and you're going to want to use a ListAdapater:
http://developer.android.com/guide/topics/ui/layout/listview.html
http://developer.android.com/reference/android/widget/Adapter.html
Basically what's going on is you're loading a large number of images into memory, and the scroll view by default doesn't do a very good job of managing releasing and inflating these resources.
Using methods similar to the above, with some custom image management, I've managed to get thousands of views running smoothly on a scroll.
It seems like you're trying to create your own list view implementation so that you can set your own layouts for each row. I don't recommend doing this. Instead, use the default list view implementation provided by Android and instead of setting a default ArrayAdapter instance on the list view, subclass ArrayAdapter, override the getView method, and return your custom layout.
I highly recommend you check out this tutorial for a more thorough explanation:
http://www.ezzylearning.com/tutorial.aspx?tid=1763429

How to prevent ListView items highlighting in Black

I have been trying desperately to fix this issue where my ListView items are highlighted. I have reviewed any solution I could find here on stackoverflow, and have found none that work for me.
First off, this is a ListView in a LinearLayout in a ViewPager in a LinearLayout.
Each Item in that Listview is a LinearLayout containing a LinearLayout (Containing a TextView) and a Gallery. The Gallery contains multiple LinearLayouts containing a TextView and Imageview in a FrameLayout.
This problem occurs, not on click but on drag, as when swiping your finger over a story (sometimes while the ListView scrolls with your drag) the item underneath becomes selected. Additionally, this particular problem only occurs on devices where the over-scroll effect does not cause a bounce when scrolling.
Attempts to solve the issue are as follows:
Set the List Selector to the Background Color in XML (Fail)
Set the List Select to Alpha #00000000 in XML (Fail)
The Above but Programatically
The Above but by theme
Code that sets the selection to -1 onListItemClick
Removing the background from list item's LinearLayout (Works on 4.0)
Setting android:cacheColorHint to #00000000 (does nothing?)
I just can't figure out why it's doing this and I really need it to stop.
This was a most interesting problem. The solution of which is even more interesting.
For some reason, what I didn't try, and what nobody thought of, was to remove android:background from the LinearLayout for the ListView items.
Upon removing android:background, the layout continues to display properly and the black no longer appears.
If you have a problem similar to this that this does not solve, you may want to check the Android Blog: Why is my list black?
EDIT: This worked fine for ICS, but elicited a much larger problem in 2.1. To completely solve the ordeal, I ended up having to specify android:cacheColorHint="#000000" to the ListView (and the LinearLayout for good measure) in my inline styles as well as in the style definition I applied to the ListView.

Highlight selected cell with background image

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.

Categories

Resources