Android 用于高度大于宽度的屏幕的工作室布局资源

Android studio layout resource for screens with height bigger than width

在 android studio 中,我知道,例如,如果我将创建一个名为 layout-sw600dp 的文件夹,该文件夹中的布局文件将用于宽度至少为 600dp 的屏幕。我想知道有没有办法命名一个文件夹,该文件夹将用于高度大于宽度的屏幕?如果没有办法,如何创建这样的行为(即高度大于宽度和宽度大于高度的屏幕的单独布局)?

您可以使用此代码测量设备的高度和宽度:

View view = getLayoutInflater().inflate(R.layout.your_activity, null); 
//For example, linear layout
LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.yourlinearlayout);
linearLayout.measure(0,0); 
int width = linearLayout.getMeasuredWidth();
int height = linearLayout.getMeasuredHeight();
if(width > height) {
   // your code here
} 

您可以使用文件夹名称 layout-port - 表示设备处于纵向模式(高大于宽)或 layout-land 用于横向模式(宽大于高)。

有关可用选项的详细信息,请参阅 here

有些屏幕尺寸的宽度大于高度(例如平板电脑)。 您可以在 xml 中使用布局文件夹中的“-long”“-notlong”后缀检查屏幕方面。

This is based purely on the aspect ratio of the screen (a "long" screen is wider). This isn't related to the screen orientation.

>long: Long screens, such as WQVGA, WVGA, FWVGA
>notlong: Not long screens, such as QVGA, HVGA, and VGA

https://developer.android.com/guide/topics/resources/providing-resources