I have a ListActivity with a ListView and everything works great; however I am trying to set a background image and the image is appearing in each row and making the row very tall.
How do I make the background for that view so the rows don't pick up the image?
In onCreate() of your ListActivity, call
getListView().setCacheColorHint(0);
getListView().setBackgroundResource(R.drawable.backgroundresource);
Without the .setCacheColorHint(0) the background will flash to the original background color every time you scroll. With it added the background is a constant. (Thanks Matt it fixed that issue for me).
maybe you are attaching the background to the list item, be sure to do this in your ListActivity:
getListView().setBackgroundResource(...)
Related
I am unable to get the first button in a gridView to change colour. The button works fine, and it operates as normal when it is clickd but it wont update the colour of the first button. I am using a custom list adapter to generate the gridView. This only seems to happen if I want to change it in real time, if i load the buttons at a later stage the buttons do change colour. I've tried to hard code it for the first button in the list but that doesn't seem to work either.
In Grid view First you have to create a custom adapter for it and then in the Override method "get View()" you will get the specific cell and then change its background color.
For Details click the link : https://developer.android.com/guide/topics/ui/layout/gridview.html
I have a doubt I have a listview and below it there is a background with a image. I would like to have the lists with a transparent color in order to see the image in the background with the ListViews color. I have tried using a selector but it just applies to the select item i the listview.
Maybe it is not very clear so for that purpose I attach the following picture where the listview and the background is shown:
As you can see the item background is with color but the image is still visible
Thank you very much
Add following property in ListView...
android:cacheColorHint="#00000000"
it is for transparent background of ListView.
More detail see Here.
You can also use an image editor to edit the opacity of the image/shape/gradient/whatever that you're using for the rows. I use Gimp because it's free. Here's what you need to do in Gimp: Go to the 'Layers - Brushes' window. Right-click the image layer and 'Add Alpha Channel'. Then just dial down the Opacity using the number picker (located above the layer) and File -> Export the image. Add this image to your project. Set it as the background for the List View rows. Then set the background for the List View itself to whatever you want to take up the entire background behind the List View.
I managed to achieve this with the RecyclerView by adding this line of code to the 'onBindViewHolder' method in the 'RecyclerView.Adapter' class:
((RelativeLayout) holder.itemView).getChildAt(0).setBackgroundColor(Color.parseColor("#00FFFFFF"));
Bear in mind that the view returned by the above cast expression is an 'android.support.v7.widget.CardView' that contains the list item layout
In the native Gallery app on Android, when Select item via Option Menu action, you can select multiple items, each grid item which will have a colored-border overlay on top signify as selected when clicked.
Question:
How to do this dynamically using getView() in the ImageAdapter
class? (since there is setBackgroundColor() but not setBorder()
Is there a better way to accomplish this? (such as creating a padding
of some sort for the image within the gridview cell, then set the
background color which will look like a border)
I finally decided to use the 2nd method in the original post: creating a padding for ImageView within the gridview cell and set the background color.
I used ImageView.ScaleType.CENTER_CROP with setCropToPadding(true); for the ImageView.
I have a listview to which i attach data using an Array adapter.
But when i scroll, i find the edges to be dark.
Why is this happening and how to stop it.
Any help please!!
That is just a hint that there is more data present at the end of the list.
try using
android:cacheColorHint="#00000000"
This will help
If u add TextViews or Different Views to listview apply listview background color to background color of those views .then u did not get the black screen when u scroll the listview
How does the hierarchy of your activity look like? If your UI only contains a ListView then it's easier to just inherit from ListActivity
I am using customadapter to set data for list which contains a text view, imageview and a layout with some buttons. the buttons layout will be invisible initially. When we click on list item the layout has to appear with user able to click a button. This work fine as long as ImageView is static.
But our build will fetch image from url and set it to view. Here the refresh issue arises. The Layout is unable to be view.
List refreshes when re apply any external even such as Track ball or scroll.
Please help me regarding this.....
Without actual code, it's hard to tell what the problem is, but have you tried calling invalidate() (inside UI thread) or postInvalidate() (outside UI thread) on the layout or any view you need to redraw? This forces the view to call onDraw() again.