Issue
In my code I have many icons which are used in application. Now I want to change all icons with all its sizes like hdpi, xhdpi ect.
How to change all sizes of icons in a shortcut way? Please suggest me.
Solution
You can use this library to make things easier for you to manipulate drawable in different screen sizes.
Here is the Library
You can put the height and width in SDP it will manage itself for all screens
For example like this
<ImageView
android:id="@+id/ivImage"
android:layout_width="@dimen/_9sdp"
android:layout_height="@dimen/_18sdp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/icon" />
OR
Using this code you can get runtime Display's Width & Height
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;
In a view you need to do something like this:
((Activity) getContext()).getWindowManager()
.getDefaultDisplay()
.getMetrics(displayMetrics);
You can get the screen sizes and manage itself.
Answered By - Tanveer Munir
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.