Multiple Screen Resolution

I am developing an application in 320 * 480. How do I get the application to run on a 480 * 854 screen? When I tried to run the 480 * 854 screen, the original design of the application looks like a small one. I want to create separate layouts for each screen in Android? If yes, please provide me an example of a hint.

+3
android screen-resolution
Aug 23 '11 at 5:45 a.m.
source share
5 answers

I implemented my own way of handling multiple screen resolutions .

You could avoid this problem by setting LayoutParams at runtime in terms of Percentage

Problem occurs only with Views/Layouts , which has some constant width or height allows 280dp . The solution is quite simple if we programmatically set the Layout Parameters of our Views/Layouts in terms of Percentage and use only the width or height constant, where necessary, try using match_parent to fill in the empty space or using weights and define each View compared to the other Views , this will help your layout look good in almost all screen resolutions

Here is an xml example

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/mLayout" android:layout_width="280px" android:layout_height="300px" /> </RelativeLayout> 

Note: I used px for a fixed width / height layout, because in LayoutParams layoutParams = new LayoutParams(int width, int height); width and height read pixel value

Here is an example installation code Width and Height as a percentage

 final ViewTreeObserver mLayoutObserver = mLayout.getViewTreeObserver(); mLayoutObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { DisplayMetrics metrics = getResources().getDisplayMetrics(); int deviceWidth = metrics.widthPixels; int deviceHeight = metrics.heightPixels; float widthInPercentage = ( (float) 280 / 320 ) * 100; float heightInPercentage = ( (float) 300 / 480 ) * 100; int mLayoutWidth = (int) ( (widthInPercentage * deviceWidth) / 100 ); int mLayoutHeight = (int) ( (heightInPercentage * deviceHeight) / 100 ); LayoutParams layoutParams = new LayoutParams(mLayoutWidth, mLayoutHeight); mLayout.setLayoutParams(layoutParams); } }); 

Now, perhaps some people are wondering what is going on here.

float widthInPercentage = ( (float) 280 / 320 ) * 100

Let me explain 280 - the width of my LinearLayout and 320 - is the width of the screen of my device (which I am developing), I know that I am currently testing a device with a resolution of 320 x 480 , what I am doing is calculating how much area my layout covers in terms of percentage and then

int mLayoutWidth = (int) ( (widthInPercentage * deviceWidth) / 100 )

Here I calculate the new width for my layout according to the screen resolution, and this way your Views/Layouts will look exactly the same at every screen resolution .

Conclusion: If you need to set the width / height constant for your Views/Layouts always set value in px in the layout file (i.e. xml), and then programmatically set LayoutParams .

Suggestion for Google Android developers , I think you guys should seriously consider changing dp/dip units to percentage

+8
May 13, '13 at 9:17
source share

To do this, you can make your layout dynamic with a link to the available width and height of the device

 Display mDisplay= activity.getWindowManager().getDefaultDisplay(); int width= mDisplay.getWidth(); int Height= mDisplay.getHeight(); 

set your layout in terms of duration with reference to size avail

+2
Aug 23 2018-11-11T00:
source share

city ​​of Babar,

I think you should follow the formula below and not calculate how

 float widthInPercentage = ( (float) 280 / 320 ) * 100; float heightInPercentage = ( (float) 300 / 480 ) * 100; int mLayoutWidth = (int) ( (widthInPercentage * deviceWidth) / 100 ); int mLayoutHeight = (int) ( (heightInPercentage * deviceHeight) / 100 ); 

I would suggest that if you do this as follows:

 int baseWidth=320; int baseHeight=480; int mLayoutWidth = (int) ( (280* deviceWidth) / baseWidth); int mLayoutHeight = (int) ( (300* deviceHeight) / baseHeight); 

It will also work for views, not text sizes;

+1
Oct 08 '13 at 7:36
source share

In Android, you don't go by absolute resolution, but rather concentrate on screen density. And yes, you may need to create a different layout to support different screen sizes and sizes. In general, there are four densities supported by Android (low, medium, high, very high)

I suggest you read Multi-screen support for Android. I think this will help you achieve what you need. It has various sections on the development of alternative layouts and drawings and other useful information related to the support of multiple screen resolutions.

0
Aug 23 2018-11-11T00:
source share

hi welcome stack overflow ...
Starting with version 1.6, Android supports several screen resolutions and densities, divided into three classes:

  • Small: devices with a screen size smaller than the T-Mobile G1 or Samsung I7500, e.g. HTC Tattoo
  • Normal: devices with a screen size of about the same as the G1 or I7500.
  • Large: devices with a screen size larger than the G1 or I7500 (such as a tablet-style device).

Developers can control when and how applications appear on devices in each group using the tools provided in the Android APIs and SDKs. Implementation details can be found in the Android Dev Guide. Support for multiple screens. you can refer to this link MultiResolution

or can use

 Display displayparm= activity.getWindowManager().getDefaultDisplay(); int width= displayparm.getWidth(); int Height= displayparm.getHeight(); 
0
Aug 23 2018-11-11T00:
source share



All Articles