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.
Related
I want to acheive the following. Transparent background with white tick
How do i get the white tick mark on the transparent background.
i tried the following.
viewprev = mgridview.getChildAt(i - mgridview.getFirstVisiblePosition());
viewprev.setBackgroundColor(Color.WHITE);
viewprev.setAlpha(0.5f);
Try this out,
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/ivMain"
android:layout_width="200dp"
android:layout_height="200dp"
android:contentDescription="#string/app_name"
android:src="#mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout
android:layout_width="150dp"
android:layout_height="150dp"
android:background="#99676767"
app:layout_constraintBottom_toBottomOf="#id/ivMain"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#id/ivMain">
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:layout_gravity="center"
android:contentDescription="#string/app_name"
android:src="#drawable/vector_favorite" />
</FrameLayout>
Your tick should be in the FrameLayout which should be constrainted as in the code so its always in the middle of the ImageView. From the image I guess you're trying to create a long click to select items kind of thing. If so just set the visibility of FrameLayout to gone in xml and in LongClick event set it to visible
This is the output of above code:
You can play around with the color to achieve your desired transparency level
You may need to use FrameLayout.The Framelayout contains your image and an empty ImageView above it. When you need to draw a tick - just set its image into that ImageView.
First you need to add an ImageView to your grid item layout. Remember to insert the xml tag below the main grid image in order to appear on top. Then use match_parent as the image view width and height and assign the scaleType to center. This is your check mark view. You can add a semi transparent background to make a shade above the grid item image and the src attribute goes to the check mark.
You can also modify the image view visibility toggle hide and show of the check mark item.
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 .
I know similar questions asked a lot of times but this one is different. I've got a background image and I am supposed to use this for ImageViews. Picture is not rectangular and not transparent, you can view it from here or see below
This is what I've tried:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#999999"
android:padding="10dp"
android:gravity="center">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="170dp">
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/rounded_background"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/random_pic"
android:scaleType="fitXY"/>
</FrameLayout>
</LinearLayout>
and result looks like this:
When I remove the ImageView result is this:
As you can see, ImageView doesn't have the same shape as background. I've tried several different methods as well, like
putting background directly to the ImageView, or
changing the View to ImageView and use the rounded image as background, or source image of it
they had no effect. I've also tried to change the order, I've put the View after the ImageView, but then since the rounded background is not transparent, I couldn't see the ImageView, all I saw was the white background image.
It is not possible to achieve without changing the rounded_background.png file itself, right? Cause I know that if the background was transparent it would've worked.
Thanks
EDIT: There is no way to achieve this without changing the image. If one wants to learn the only way to achieve that, he/she should see the accepted answer.
Here is your problem solution.
make your background image transparent like this.
set your main image as FrameLayout background image.
and this background is ImageView background image.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="170dp"
android:background="#drawable/randominage">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/rounded_background"
android:scaleType="fitXY" />
</FrameLayout>
This is my Android list_item layout XML:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingRight="?android:attr/scrollbarSize"
android:background="#drawable/list_bg">
<TextView
android:id="#+id/tv_displayname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:ellipsize="end"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
This is the list_bg image:
and yet here is what it looks like when shown in Android emulator:
I can see that the background is being applied because there is a slight gradient effect to it, but I have no idea where this black overlay is coming from!
have you tried a different image to see if that one does the same thing? to me it looks like it is creating the image behind the list in your RelativeLayout and your textview background is on top. since you are setting it to fill the width of the row, i bet if you just set to wrap_content you would see it behind there
try putting the image as your TextView background instead
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.