android patch 9 lose after load a dynamic image - android

My linearLayout backgroud is losing is patch 9 effet after the imageView is load from a dynamic Url
the only way to fix the problem is to use holder.imgView.setScaleType(ImageView.ScaleType.FIT_XY);
but i don't want to stretch the image at the same time
<LinearLayout
android:id="#+id/llPatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/testt1"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageRecette"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:padding="0dp"
android:src="#drawable/tartare" />
</LinearLayout>

9-patch images are compiled with the project (from your res folder).
You can see how a compiled 9-patch looks like if you add one to a project, build it (the project) and look in bin/res/[where your image is at]/[image name].9.png
So you can't load a 9-patch image (with the lines on the sides) from a url.
You can however upload a compiled 9-patch to your server, download it and use it as specified here:
https://stackoverflow.com/a/10639923/876603

Related

Android Studio and PNG vector images

Creating vector images in Photoshop (for transparent backgrounds). When I add them as the image source for my ImageButtons, and run the app, the image displays with a white background.
Can't find any useful info on why the images are not coming out transparent through the app.
Are there some additional steps/coding required to make vector images work properly? I can't see why.
Example code, as requested:
<ImageButton
android:id="#+id/btnGameUp"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/arrowright"
android:adjustViewBounds="false"
android:clickable="true"
android:cropToPadding="false"
android:padding="0dp"
android:scaleType="fitXY"
android:layout_marginLeft="270dp"
android:layout_marginTop="260dp" />
No one came to help us, but we managed to find the solution on our own after hours of crying and holding each other for comfort.
In the layout xml file, you need to add the following line to each vector object:
android:background="#android:color/transparent"
That's it! Tested and working perfectly. Hope this helps someone.

android imageview got distortion after being completely downloaded

As you all see in attachment, android imageview got distortion after being completely downloaded with using coding of following link Load images from web and caching.
here is my imageview tag and original image resolution is 850x315.
<ImageView
android:paddingTop="10dip"
android:paddingBottom="5dip"
android:id="#+id/idThumb"
android:layout_width="match_parent"
android:layout_height="70dp"
android:contentDescription="#string/app_name"
android:scaleType="centerCrop"
android:src="#drawable/no_image" />
Please check me why this ImageView cannot fetch original resolution of image from URL and got blur.!
gotta use WebView instead of ImageView will fulfilled what I want.

Background image crashes android

My application crashes when i put background line like in this code. When i delete this line my application works fine and also when i use another photo it also works. What's the problem?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/table2" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
The background for the main screen works fine also. But in the second page, it is problamatic.
If you are using only drawable folder to store all images.then change storage folder for high resolution images in drawable-xhdpi folder or higher.
Hope this helps.
Thanks to you all. I changed the dimensions from 2500x1900 to 1280x920, now it works.
Make sure about the image path if it is in drawable folder..put it inside Mipmap folder in your project directory.
I think you should check the size of your image anything above 300kb may tend to constantly crash your app. You can always use image compression Softwares to reduce the size of your image.

Android - ImageView does not display image. Nor does setImageResource()

I use an ImageView control as shown:
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/imgHangMan"
android:src="#drawable/hang0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
The above code displays the image in the Graphical Layout preview of the xml file. But on launching the app, I see no image. Also, changing the image using
imgHangMan = (ImageView)findViewById(R.id.imgHangMan);
imgHangMan.setImageResource(R.drawable.hang1);
This piece of code also does not work either. The image files are in .gif format and are in the drawable folder.
Any pointers ?
Natively ImageView doesnot support animated image. You have two options to show animated gif file
1) Use VideoView 2) Use ImageView. But Split the gif file into several parts and then apply animation to it.
Try this link-playing-gif-animation you will get the desired result.
Try this
image.setImageDrawable(getResources().getDrawable(R.drawable.hang1));
User this :
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
Go by this.

TextView Background Resource

I implemented the following TextView in a RelativeView:
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/bg"/>
The problem is that the size will be set dynamically to 15% of the screen while the application is running. But when I do this the background ressource doesn't get the size of the TextView. It has the original size of 150x150 px. What can I do to avoid this?
(I don't want to take a smaller ressource because it doesn't look well then)
Try using another scaleType, for example android:scaleType="fitXY".
Also you can try making a nine-patch image. To do this, go to your Android SDK folder - tools - draw9patch application. Then you will have options to open your image and then save it as nine-patch image. Reference it as usual in your layout.

Categories

Resources