I want show image in ImageView, but don't show it. I use XML code and Java code but don't show. show in simulator but in real devices don't show. tested on LG G2, HTC One X, Samsung Galaxy S3.
my xml code :
<ImageView
android:id="#+id/sms_dialog_header"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:background="#drawable/show_sms_header" />
my java code :
Dialog_Header_Img = (ImageView) findViewById(R.id.sms_dialog_header);
Dialog_Header_Img.setImageResource(R.drawable.show_sms_header);
I used to be separated from each.
Please tell me the solution
First of all you should set image in xml by code:
android:src="#drawable/show_sms_header"
not by android:background, well you can set background to color or other image but your main image you should set by android:src
If you changing something about your image, leave first line in your code that you show, and delete second, if setting image is only thing you set, then you can delete both, because you set source of image in xml.
The "src" attribute should be set to your drawable if you want it to be "centerCrop" correctly.
Check this out :
<ImageView
android:id="#+id/sms_dialog_header"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="#drawable/show_sms_header" />
Make sure that your file, called "show_sms_header", is in your drawable ( /res/drawable) directory.
Related
I'm development a app with a m3u8 transmission using exoplayer, and some times my transmission is offline, so a need to show a background image with it happenes, and i now find no options to solve this. The only thing with i can find is a shutter_background_color propertieswho define a color of the background player, but this not solve my problem. I need to show a bitmap image.
Please help!!!
<com.google.android.exoplayer2.ui.PlayerView
android:id="#+id/pl_aovivo"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:resize_mode="fit"
app:use_artwork="true"
app:shutter_background_color="#color/colorPrimary" />
Don't use artwork for this. The best you can do is to add an invisible ImageView inside the layout that host your PlayerView and just turn it visible when onPlayerError occurs.
If you have to set place holder image on to exo player than use below code:
<com.google.android.exoplayer2.ui.PlayerView
android:id="#+id/video_player"
android:layout_width="match_parent"
android:layout_height="#dimen/_150sdp"
android:layout_centerInParent="true"
android:visibility="visible"
app:default_artwork="#drawable/default_media_artwork"
app:use_artwork="true"
app:resize_mode="fixed_width"
app:show_buffering="when_playing" />
Preamble
I've been g00gling for half an hour now, and it seems like I'm really missing something important.
Note: I've already tried the solutions for these questions
How to change color of vector drawable path on button click
How to set tint for an image view programmatically in android?
Changing ImageView source
These solutions either recolor ALL ImageView srcs or they don't do anything at all (vector remains black).
My drawable is a vector asset from the material icons directory:
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2z" />
</vector>
My ImageView:
<ImageView
android:id="#+id/gradeBullet"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="25.5dp"
android:layout_marginTop="25.5dp"
app:srcCompat="#drawable/importantgrade" />
I would like to do this with *Compat, because I'd also like to support earlier APIs (API>17).
My ImageView: ImageView gradeBullet = convertView.findViewById(R.id.gradeBullet);
Try I.
MyAmazingAdapter.java - getChildView(...)
gradeBullet.setColorFilter(ContextCompat.getColor(context, gradeObj.colorId), PorterDuff.Mode.MULTIPLY);
Result: Does nothing.
Try II.
MyAmazingAdapter.java - getChildView(...)
DrawableCompat.setTint(gradeBullet.getDrawable(), ContextCompat.getColor(context, R.color.myColor));
Result: Recolors everything.
Try III.
MyAmazingAdapter.java - getChildView(...)
VectorDrawableCompat drawable = (VectorDrawableCompat) gradeBullet.getDrawable();
drawable.setTint(ContextCompat.getColor(context, gradeObj.colorId));
gradeBullet.setImageDrawable(drawable);
Result: Gives a weird color. (Definitely not what I want, it's closer to the original color)
Try IV.
All the above with a final to the gradeBullet, got the same results.
Some other info
The gradeObj.colorId is different for every childView.
Using shapes and setColor instead of SVG is not what I want.
Currently only tested with API lvl 26
MyAmazingAdapter.java extends BaseExpandableListAdapter
If you'd like more info, just mention it in a comment.
You can try your first method with PorterDuff.Mode.SRC_IN or PorterDuff.Mode.SRC_ATOP instead of PorterDuff.Mode.MULTIPLY.
PorterDuff.mode
Hope this helps.
I've been working on a simple java application, and wanted to add a logo as the homescreen is fairly empty. I tried using an image view, and after it didn't work I googled tutorials to make sure I was initiating it correctly. I didn't see any difference, but the actual image wouldn't load.
Xml code for image view:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src = "#drawable/logo"
android:layout_gravity="center"
android:contentDescription="#string/logo"
android:layout_below="#+id/textView"
android:layout_above="#+id/txtBody"
android:layout_alignRight="#+id/txtBody"
android:layout_alignEnd="#+id/txtBody"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:visibility="visible"
android:maxHeight="600dp"
android:maxWidth="600dp"
android:minHeight="100dp"
android:minWidth="100dp"
android:clickable="false" />
And here's a picture of the layout preview (With an arrow pointing to the outline of where it should be, and the resource circled in the correct folder) along with a picture of the logo
Any dice if you add
android:scaleType="fitCenter"
android:adjustViewBounds="true"
Edit: also are we sure nothing is overlapping it?
Looking at the code below;
ImageView theImageView = (ImageView) theView.findViewById(R.id.imageView1);
theImageView.setImageResource(R.drawable.dot);
Is the second line necessary if we established the source (android:src) of the image in the xml file? XML shown below;
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="25dp"
android:src="#drawable/dot"
android:id="#+id/imageView1"/>
No. You either do it in XML or in Java code. You don't have to do it twice.
If you have already define ImageView and set image, then you don't even have to get it's reference in Java code (1st line), unless you want to change something.
I have imageview with resolution of 430x871 in folders xxhdpi, xhdpi and hdpi. But when I run app, on 5" Xperia Z (xxhdpi) screen it works normally (1. picture) but on 4.7" Amazon Phone (xhdpi) it's smaller (2. picture). Altough when I run it on Amazon Fire HD 8.9 or 7 or 6, (all xdpi) it works too...
How can I stretch in on that Amazon Phone?
Here is XML code of the Imageview:
<ImageView
android:id="#+id/matter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:gravity="center"
android:src="#drawable/matter"
/>
if aspect ratio is not important for you use:
android:scaleType="fitXY"
but if yes try this:
android:scaleType="fitCenter"
and also change this:
android:layout_height="match_parent"
There's a property called :
android:scaleType="fitXY"
inside ImageView tag.