Scaling Imagebuttons For Various Screen Sizes
Solution 1:
First you will have to change your Button to take up the whole screen:
<Button
android:layout_width="match_parent"android:layout_height="match_parent"android:id="@+id/exitBtn"android:layout_marginBottom="52dp" <-- You may keep the margin if you likeandroid:background="@drawable/popup_btn"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true" />
Next you will have to include different resources for the different densities that you will support: mdpi, xhpdi, xxhdpi, and so on. Please make sure the resolution is appropriate for each one and avoid using the same image, files that are too big will take up memory and processing power, files are too small in resolution will look pixelated.
Edit: More on supporting different devices and screen densities: http://developer.android.com/guide/practices/screens_support.html
Solution 2:
for compatible your layouts with different screen sizes you should use dimens under res/ directory for layouts compatibility for example you can define different dimens for different screen sizes see also Providing Resources and Supporting Multiple Screens
Solution 3:
create display metrics by instantiating it .now from display metrics retrieve the width and height of your whole root view
Once done implement the globallayoutchangelistener in Oncreate of your activity and place your scaling code inside the listener .
Idea is to calculate the device density first and then scale the button according to density in globallayoutchangelistener
Let me know if it works .
Post a Comment for "Scaling Imagebuttons For Various Screen Sizes"