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.
Related
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
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.
When trying to add a custom image to a ImageButton, I get the following error:
E/AndroidRuntime(3304): Caused by: java.io.FileNotFoundException: res/drawable/btn_default.xml
This Works:
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/btn_plus" />
This does not:
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/elec" />
On the designer I can see the image fine on the button, but as soon as I try to run it, I get the above error. The elec.png file is in drawable-hdpi.
Burned 3 hours trying to find the problem. Any help really appreciated!
You should also put you image in the drawable folder ( + correctly sized version in drawable-ldpi, drawable-mdpi, drawable-xhdpi to follow Android guidelines )
In the end, it turned out that my emulator was somehow corrupted. The code works perfectly on a real device and on a newly generated emulator.
I am trying to partially change the images for Android's checkboxes. Following the tutorial here, I have done the following experiment:
<CheckBox
android:checked="true"
android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<CheckBox
android:checked="true"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:button="#android:drawable/btn_check_on"
android:background="#android:drawable/btn_check_label_background"/>
<CheckBox
android:checked="true"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:button="#drawable/cb_on"
android:background="#drawable/cb_background"/>
For the third checkbox, I have copied the images btn_check_on.png and btn_check_label_background.9.png from Android's SDK to the project's res/drawable and rename them to cb_on.png and cb_background.png. While I expected the three checkboxes to have identical appearances, surprisingly, the third checkbox is larger than the first two. Can anybody explain why? How can I fix this problem?
Try renaming your image cb_background.png in cb_background.9.png
.9 means that the image is a nine-patch image which is done to rescale itself automatically.
I think that why the third image is larger.
For more information about nine-patch: here
My guess would be that you only copied one resolution of the drawables. You need to copy all of them (mdpi, hdpi,ldpi) to the appropriate res folder (drawable-mdpi, drawable-hdpi, drawable-ldpi)
#Jokahero is right about the 9-patch, and #jkhouw1 is right about the resolutions. For checkboxes, you will also need to know about StateListDrawable.
I'm using layout xml file for the UI. But the images are compressed and the qualities have lost in some level.
My code is like this:
<ImageView
android:layout_width="480px"
android:layout_height="717px"
android:layout_x="0px"
android:layout_y="45px"
android:scaleType="fitXY"
android:src="#drawable/e4" />
The drawable is actually 480x717.
What's the problem here? Is it due to the fitXY?
Of course it is.
You say you want some dimensions, but then you say you want to scale it.
So it scales it.