Android Radio Button PNG Drawable top - android

I have a Radio Group. 5 Radio Buttons. The Radio Button's DrawableTop are set as, android:drawableTop="#drawable/Timeline_icon_drawable"
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="#mipmap/explore_icon_pressed" />
<item android:drawable="#mipmap/explore_icon" />
</selector>
How do I make the png smaller?

click on this link.. and download this 9 PATCH RESIZER..
9PATCH-RESIZER
It is specifically designed for developers of android. when you will drag any image on this software it will create every version of drawable images such as
xxxhdpi, xxhdpi, xhdpi, hdpi, mdpi, ldpi.
after customizing png or icon with this software you can use it comfortably in your app.
hope it helps!

Related

Android splash screen stretches a logo on the full screen

I have a simple splash screen with a white background and the logo on the center of the screen. In a modern version of the Android, its work well but in 'old' versions of Android(for example API 22) my a logo is stretched on the full screen. How to make the logo splash screen look normal on all the version of Android (before API 19)?
p.s. I`m not the Android developer.
drawable/background_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/white" />
<item
android:width="150dp"
android:height="50dp"
android:drawable="#mipmap/my_logo"
android:gravity="center" />
</layer-list>
values/styles.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">#color/white</item>
</style>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
<item name="android:statusBarColor">#color/white</item>
</style>
</resources>
Instead of using a simple <item/> tag, use a <bitmap/> tag inside of an <item>.
From the Layer List drawable documentation:
All drawable items are scaled to fit the size of the containing View, by default. [...] To avoid scaling items in the list, use a <bitmap> element inside the <item> element to specify the drawable and define the gravity to something that does not scale, such as "center".
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#color/white" />
<item>
<bitmap
android:src="#mipmap/my_logo"
android:gravity="center"/>
</item>
</layer-list>
This is because the attributes android:width and android:height were introduced in API level 23. The only solution I can think of if you want to show the same image with a relative size according to the screen size is to provide alternative bitmap resources.
Here is a link to the Android Developer Guide which explains this a bit further.
First thing doesn't use a png use a vector drawable. This way you don't need a separate image for different screen size. Use this to convert image http://a-student.github.io/SvgToVectorDrawableConverter.Web/
and now in your image view in XML file set your scale type to Center Crop or Fit XY
android:scaleType="centerCrop" or use android:scaleType="fitxy"
The issue is not related to Android version. it should be related to the screen size of Devices.
To declare different layouts and bitmaps you'd like to use for the different screens, you must place these alternative resources in separate directories/folders.
This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 100x100 for mdpi, and 75x75 for ldpi devices.
In a word, Android apps should provide 6 image sizes: ldpi (0.75x), mdpi (1.0x), hdpi (1.5x), xhdpi (2.0x), xxhdpi (3.0x), and xxxhdpi (4.0x).
What I usually do is I make sure my layout's root node is a RelativeLayout, and the first child is an ImageView with centerCrop as the scaleType.
Here's an example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:scaleType="centerCrop"
android:background="#drawable/img_background"/>
...

Add image from mipmap in android drawable item part

Below is my drawable code. I want add image from mipmap in drawable item instead use of drawable.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/drawable_selected_indicator"
android:state_selected="true"/>
<item android:drawable="#drawable/drawable_default_indicator"/>
</selector>
You can use #mipmap/fileName in your XML resources or R.mipmap.fileName in java/kotlin.
You can use #mipmap/filename to use an image from mipmap folder.
<item android:drawable="#mipmap/drawable_selected_indicator"
android:state_selected="true"/>
According to this wiki-https://github.com/codepath/android_guides/wiki/Working-with-the-ImageView
"Starting with Android 4.3, there is now an option to use the res/mipmap folder to store "mipmap" images. Mipmaps are most commonly used for application icons such as the launcher icon. To learn more about the benefits of mipmaps be sure to check out the mipmapping for drawables post.
Mipmap image resources can then be accessed using the #mipmap/ic_launcher notation in place of #drawable. Placing icons in mipmap folders (rather than drawable) is considered a best practice because they can often be used at resolutions different from the device’s current density. For example, an xxxhdpi app icon might be used on the launcher for an xxhdpi device."

Android drawable item size on different resolutions

Is it possible to get correctly scaled item drawable in android layer-list item?
I prepared something like this:
bg.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/splash_bg" />
<item
android:gravity="center"
android:drawable="#drawable/logo_white">
</item>
</layer-list>
The sizes for drawable/logo_white vector has: 200dp width and 100dp height. It looks nice for small devices, but on tablet this logo is too small.
Is it possible to make it responsive for bigger screens?
Many thanks for help.
You can use attribute width and height in API level 23 and higher:
<item
android:width="#dimen/your_size" android:height="#dimen/your_size"
android:drawable="#drawable/logo_white"/>
And create different dimens files, for normal phones, tab, etc
Android has multiple folder system for multiple resolutions.
layout-hdpi,
layout-xhdpi, etc.
and same goes for drawable folder too. So by implementing same filename but edited xml based on dimension for different folder you can make in responsive. You might find other different technique for this.

Android - How to implement 9 patch?

I've created some 9-patch image files using Photoshop and the Draw9Patch tool, but as I tried to implement the images, it seems like a bust. I was following this tutorial (http://www.devahead.com/blog/2011/08/creating-a-custom-android-button-with-a-resizable-skin/). Any reason this may not work? I pasted the 4 images to the drawable-hdpi, and created a new values XML called "buttons.xml" and I placed the code in that XML file:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/default_disabled" android:state_enabled="false"/>
<item android:drawable="#drawable/default_pressed" android:state_pressed="true"/>
<item android:drawable="#drawable/default_focused" android:state_focused="true"/>
<item android:drawable="#drawable/default_normal"/>
</selector>
"default_(state)" are the names of the files (with .9.png extension). And I attempted to set the background of a button to android:background="#drawable/buttons"
Where did I go wrong?
Remember, different devices have different resolutions and densities.
In your case, you have put those drawables in drawable-hdpi, so you need device with HDPI density to work, otherwise you can put those drawables in drawable folder, so all devices (i.e. mdpi, hdpi, xdpi, etc) can use those drawables.
Read about multiple screen resolutions and densities here:
http://developer.android.com/guide/practices/screens_support.html

Android icons get stretched on Samsung device

I have used my custom images to develop several Action bar and tab icons using android icon set and use them as button backgrounds. They look fine on mobile handsets but when i test on Samsung galaxy tab 7", they feel stretched and blur.
I have tried making folders layout-sw600dp and layout-large but makes no difference.
One of the icons:
<ImageButton
android:id="#+id/button_settings"
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/settings_custom"
android:focusable="true"
android:contentDescription="#string/settings"/>
settings_custom.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_action_app_sett" android:state_pressed="true"/>
<item android:drawable="#drawable/ic_action_app_sett"/>
</selector>
Can anyone help me out where am I wrong? Thank you!
Try with setting android:src="#drawable/settings_custom" , for tab 7 inch you need to put images for that resolution under drawable-large-mdpi folder, please go through below link which clear more about android support for multiple screen,
http://developer.android.com/guide/practices/screens_support.html

Categories

Resources