How to calculate dynamically pixel in android.
In android device/tablet screen size are too deferment. So as developer to hard to make code for all. In some case make UI dynamic, at that time this will help.
In this method input dp, and method will return in pixel.
This will help in making dynamic UI. like TextView, EditText, ImagesView...etc.
In android device/tablet screen size are too deferment. So as developer to hard to make code for all. In some case make UI dynamic, at that time this will help.
In this method input dp, and method will return in pixel.
This will help in making dynamic UI. like TextView, EditText, ImagesView...etc.
1 2 3 4 5 6 7 8 9 | /** * convert dp to pixel * @param dp * @return pixel of dp */ private int getPixel(int dp){ Resources r = getResources(); return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); } |
No comments:
Post a Comment