Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ho to get s8 useable screen android?

I am noob in android. My problem about useable height of 18:9 devices. When I try to get useable screen in these aspect-ratio my application is woking fine all android devices but when ı compile in Samsung Galaxy s8 it is not working. I am trying to get useable screen of devices. I have already tried method which in these links

https://stackoverflow.com/questions/43628047/how-to-support-189-aspect-ratio-in-android-apps

https://android-developers.googleblog.com/2017/03/update-your-app-to-take-advantage-of.html

And I use dynamically

DisplayMetrics metrics = this.getResources().getDisplayMetrics(); width = metrics.widthPixels; height = metrics.heightPixels ;

And I tried

private int getSoftButtonsBarHeight() {
        // getRealMetrics is only available with API 17 and +
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);
            int usableHeight = metrics.heightPixels;
            getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
            int realHeight = metrics.heightPixels;
            if (realHeight > usableHeight)
                return realHeight - usableHeight;
            else
                return 0;
        }
        return 0;
    }

And when I try to set params MATCH_PARENT height it is working good. But I need to find useable height pixel to desing my other views proportionally .

Actually these code DisplayMetrics metrics = this.getResources().getDisplayMetrics(); height = metrics.heightPixels ; working in my Activity but when I try to use it in another window which I extend from FramaLayout and add to activity it is not working.

Here is my code block

public class StudentLoginActivity extends Activity {  ...
    FrameLayout.LayoutParams containerParams = new ScrollView.LayoutParams(width, height-sb);
    container = new FrameLayout(this);
    container.setLayoutParams(containerParams);
    container.setBackgroundColor(Color.rgb(248,248,248));
    loginStudentView = new StudentLoginView(this);
    container.addView(loginStudentView); ...

}

   public class StudentLoginView extends FrameLayout { ...
    FrameLayout.LayoutParams cp = new FrameLayout.LayoutParams(width, height);
    setLayoutParams(cp); ...

}

But this problem related with android navigationBar height because when I show navigation bar there is no problem but if I hide navigationBar it is not resize application still working that there is a navigation bar on screen (but I hide the navigationBar).

My problem is very similar this link

android Navigation Bar hiding and persantage of usable screen overlap

like image 223
Kartopu Avatar asked Aug 22 '17 00:08

Kartopu


People also ask

How to quickly switch between Galaxy S8 home screen and Apps screen?

Another new feature in Galaxy S8 and S8+ is the quick switch between Galaxy S8 Home screen and Galaxy S8 Apps screen (aka app drawer). As explained in this guide, you can quickly switch between Galaxy S8 Home screen and Apps screen by swiping upwards or downwards.

Does Galaxy S8 have context menu in home screen?

Although Galaxy S8 or S8 was shipped with Android Nougat 7.0, not Android 7.1, Samsung introduced the context menu in Galaxy S8 Home screen. The context menu is similar, and even more powerful thanapp shortcuts introduced in Android Nougat 7.1. Components of Galaxy S8 Home screen

Does Galaxy S8 or S8+ have a home button?

In addition, all Android phones have a hardware or a software home button which will bring you to the “home” of the home screen if there are more than one home screen page. Galaxy S8 or S8+ is not an exception. But in Galaxy S8 and S8+, Samsung ditched the hardware Home button and used software based navigation buttons as explained in this guide.

What happens when I delete an app from Galaxy S8 home screen?

This will reduce the number of Home screen pages in Galaxy S8 and S8+ When you delete an app folder, app shortcuts inside the app folder will also be removed from Galaxy S8 Home screen. As mentioned earlier, this does NOT uninstall the app itself. Please follow this guide on how to create and use app folders in Galaxy S8 and S8+. 3. Widget


1 Answers

You can get the useable height (even on Galaxy S8 with or without shown NavBar) with the decorview:

    //Get the correct screen size even if the device has a hideable navigation bar (e.g. the Samsung Galaxy S8)
    View decorView = getWindow().getDecorView(); //if you use this in a fragment, use getActivity before getWindow()
    Rect r = new Rect();
    decorView.getWindowVisibleDisplayFrame(r);
    int screenHeight = r.bottom; // =2220 on S8 with hidden NavBar and =2076 with enabled NavBar
    int screenWidth = r.right; // =1080 on S8
like image 157
Chris Avatar answered Oct 09 '22 23:10

Chris