【问题标题】:Android studio layout resource for screens with height bigger than width高度大于宽度的屏幕的 Android Studio 布局资源
【发布时间】:2020-06-06 17:26:16
【问题描述】:

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

【问题讨论】:

    标签: android android-studio layout screen


    【解决方案1】:

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

    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
    } 
    

    【讨论】:

      【解决方案2】:

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

      有关可用选项的更多信息,请参阅here

      【讨论】:

      • 会不会有设备纵向时宽度大于高度,纵向时设备高度大于宽度?
      【解决方案3】:

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

      这纯粹基于屏幕的纵横比(“长”屏幕更宽)。这与屏幕方向无关。

      >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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-26
        • 1970-01-01
        • 2013-03-03
        • 2012-11-01
        • 1970-01-01
        相关资源
        最近更新 更多