Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling an app or activity zoom if Setting -> Display -> Display size changed to Large or small

In my app, I don't want to allow it to resize as its creating design issues.

I have tried with android:resizeableActivity="false" in the application tag and the launcher activity tag but it didn't help.

like image 687
SportyAndroidDev Avatar asked May 09 '18 11:05

SportyAndroidDev


People also ask

How do I make my Android apps fit all screen sizes?

Simple, use relative layout with the set margin code. Set the margins between each text view, button, etc and it will look the same on every phone. android:layout_marginTop="10dp" // change Top to Bottom, Left or Right for what you need.

How do you zoom in full screen on Android?

You can switch any of the layouts (except floating the thumbnail window) to full screen mode by double-clicking your Zoom window. You can exit full screen by double-clicking again or using the Esc key on your keyboard.

How do I make my phone zoom in full screen?

Tap “Magnification gestures,” then flip the switch at the top of the screen to “On.” Now, try this: go back to the home screen, then triple-tap the display with one finger. Zoom!


Video Answer


2 Answers

I have found a solution for it.

If system text size changed or Display size set to Large (Above Android Oreo), Your app will behave as normal (No big text and and zoomed views) with below code:

        Configuration configuration = getResources().getConfiguration();
        configuration.fontScale = (float) 1; //0.85 small size, 1 normal size, 1,15 big etc
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        metrics.scaledDensity = configuration.fontScale * metrics.density;
        configuration.densityDpi = (int) getResources().getDisplayMetrics().xdpi;
        getBaseContext().getResources().updateConfiguration(configuration, metrics);
like image 93
SportyAndroidDev Avatar answered Nov 09 '22 23:11

SportyAndroidDev


I will assume you're trying to get display which doesn't change if user changes Accessibility Options on it's phone regarding UI size.

You can get this working by using DisplayMetrics.

DisplayMetrics metrics = getResources().getDisplayMetrics();

With "normal" scale factor values metrics.xdpi and metrics.densityDpi have the same value. If this is not the case, you can get "real" scale factor, that is one used when user uses normal scaling using following.

if(metrics.xdpi != metrics.densityDpi){
        Log.d(TAG,"Real scale " +  (metrics.xdpi / metrics.densityDpi)*metrics.density);
}

Than you can use said value to multiply your fixed values from layout so that it can have precise density on different screens. This would also mean that every value in layout must be using px instead of dp or sp.


While this approach would work, I would strongly recommend not to use it.

Firstly, because it is a lot of work, and it will be hard to maintain that code with future updates.

Secondly, this feature of Android is very convenient, and if your app doesn't compile with it it probably points out that you should construct your layout better.

like image 43
Gotiasits Avatar answered Nov 09 '22 23:11

Gotiasits