Android. Set ListView's background Image - android

The following code is almost the same thing I want to achieve.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg">
<ListView android:layout_height="wrap_content" android:id="#+id/levelList" android:layout_width="match_parent" android:layout_alignParentLeft="true"></ListView>
</RelativeLayout>
I want to setup a background image for the whole ListView. The problem of this code is that background image blinks or disappears on scrolling.
I use sdk 2.2 and an emulator to run the program.

You'll want to set android:cacheColorHint="#00000000" on your ListView. This will set the cacheColorHint to transparent (notice the extra 2 0's after #000000) and fix your problem. Alternatively you can set the cacheColorHint to #android:color/transparent.
You should read this page on ListView backgrounds.

Related

Removing an imageview background color

I'm using Glide library for downloading images and displaying them in my adapter, the problem is, after it sets the images, they get a background that is not in the downloaded image, the ImageView added this color to them
this is an example:
as you can see it has a very light green background color, the image it self has white background.
things I've tried so far:
set white background color in my xml layout
set transparent background color
used View.setBackgroundColor(Color.TRANSPARENT) in my adapter
used View.setBackgroundColor(0x00000000) in adapter
nothing worked...
how can I get rid of it?
::EDit
the layout file attached :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/flag"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:backgroundTint="#fff"
android:background="#fff" />
</RelativeLayout>
Look at the image, which has a white background. Try to add a transparent image and your problem will be solved. I removed the background of that image. Look at the difference between these two images.

Android ListView Layout center

I want to make a prayer time app in android as shown below. I try to make it using a Listview and background image but can not achieve it.
this is how you should go about it:
activity.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/your_image">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
In the parent set the background as your image, and populate listview with whatever data you like.

How to apply different colour filters on an image in android?

I can't figure out how can we apply filters over an image.
In this case I want the image to be darker (black, 40% transparency, layer on top of the image would give me the result I want). However, it will be helpful (in future) if I know how to put a layer over an image of any color (with some transparency) to make it more visually compatible with the other UI elements of the app.
How it looks now.
How I want it to look on the app (the above image has been edited in Adobe illustrator but the app repeatedly crashes if I use it even though its size is not large)
Also, I suspect there must be a way to do this in android studio without the need of any image editing software.
Correct me if I am wrong ;)
This is what i do ,
imageView =(ImageView) findViewById(R.id.image_view) ;
imageView.getDrawable().setColorFilter(0x76ffffff, PorterDuff.Mode.MULTIPLY );
color range [0x00000000 -0xffffffff]
If you don't understand the pattern this might help you
Red - 0xffff0000
green -0xff00ff00
blue - 0xff0000ff
your request average black color 0xff555555
change color codes as you want > here
out put
Further more :
setColorFilter params : (int color,
PorterDuff.Mode mode)
What does PorterDuff.Mode mean
You can use android:foreground property of a object to set a color over any object. here i used an ImageView to show a image and android:foreground to put a filter!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/yourImage"
android:foreground="#60000000" />
</RelativeLayout>
if you want to do this a layout then use android:background property instead of android:src for the source of image.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/yourImage"
android:foreground="#60000000">
</RelativeLayout>
Generate a 9 patch image using any online tool for the darker image and use that 9 patch in your app. it will work.
Try this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha=".5"
android:src="#drawable/your_naruto_img"/>
</RelativeLayout>
Of course you can adjust the opacity accordingly by changing android:alpha [0 - 1].
Hope this helps!
Try this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/your_drawable">
<ImageView
android:id="#+id/backImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#66000000"
android:scaleType="fitXY"/>
</RelativeLayout>
You can set the image to the background of a RelativeLayout. Use the imageview tag and set background with transparent color which you want to set.
What worked for me was
ImageView backgroundimage = FindViewById<ImageView>(Resource.Id.img_view);
backgroundimage.SetColorFilter(Color.Argb(200,0,0,0), PorterDuff.Mode.Overlay);
after trying all the above answers.
Hope it helps someone .

changing ExpandableListView background in xml

Hi I cant figure for the life of me to change the background of this to white.
CODE:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
>
<ExpandableListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
>
</ExpandableListView>
</LinearLayout>
Make the black here white
Probably going have to change the font color to black.
Can you post a screenshot of how it looks now? And perhaps a quick description of how you'd like it to look?
Does it look like you want it to but mess up when you go to scroll the list?
Check out this page for some useful info on using listviews with custom backgrounds: http://developer.android.com/resources/articles/listview-backgrounds.html
try setting the cacheColorHint:"00000000"

Background image with fading edges

I tried to put background image to linearlayout in my android project. All is working nicely except those fading edges in the left and right on the screen. My background image dimensions are 52x602 and don't have such fading edge originally. I want the background image to cover all the area. Also it has done by designer and using 9-patch I think (black border around image). How can I set the background correctly without those edges?
In emulator it looks like this:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/login_background"
android:orientation="vertical"
>
</LinearLayout>
Ok, got answer myself. The .png files must have .9.png ending if they are 9-patch files...So if someone will have same problem, then you'll know.
Try setting fadingEdge to none
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/login_background"
android:orientation="vertical"
android:fadingEdge="none"
>
</LinearLayout>

Categories

Resources