Reputation: 1639
i'm designing an app and i have several buttons displayed in a table layout. I have two devices to test the app on. One is a Samsung galaxy Tab 1 and the other is a Samsung galaxy Ace. I used the following in the android manifest file to allow resizing.
<supports-screens
android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
All the buttons also have
android:layout_weight="1".
that allows them to take up extra blank space available on the display. This works fine on the tab but on the phone some of the buttons wrap. i.e the word "button" is displayed on 2 lines. I want the buttons to resize themselves such that no button wraps height-wise on any display. Can someone tell me how to achieve this ? oh and the app was developed for android 2.3.3 .
Upvotes: 0
Views: 2486
Reputation: 2624
There are 2 ways to implement it:
(1) Put the images of suitable sizes in xhdpi,hdpi, mdpi and ldpi folders. Devices will automatically take the images from these folders according to their resolutions.
(2) You can also detect the resolution of the device dynamically and then set the layouts accordingly, like this:
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
switch(displayMetrics.densityDpi){
case DisplayMetrics.DENSITY_LOW:
// layout for small devices.
break;
case DisplayMetrics.DENSITY_MEDIUM:
// layout for medium devices.
break;
case DisplayMetrics.DENSITY_HIGH:
// layout for bigger devices.
break;
}
Upvotes: 2