【问题标题】:Android UI getting stretched widthwiseAndroid UI 横向拉伸
【发布时间】:2018-06-22 05:42:53
【问题描述】:

我有一个自定义显示器 stretched widthwise,分辨率为 1920x720,屏幕尺寸为 10.3 英寸,纵横比为 8:3。我正在为这个屏幕使用 android 演示类。使用演示类时,android 屏幕 UI 将适合显示默认没有任何底部或顶部栏(甚至没有主页或返回按钮),即整个屏幕将充满应用程序 UI。如何为此分辨率和纵横比制作 UI?为什么我的图像在我的应用程序 UI 中被横向拉伸?

【问题讨论】:

  • 您应该确保选择与您的手机屏幕纵横比相匹配的显示分辨率和图片尺寸!您会注意到 1920/720 与 8/3 不匹配,这就是您的图片被拉伸的原因。

标签: android xml android-layout android-studio-3.0 android-8.1-oreo


【解决方案1】:

对于全宽或全高图像,您必须像这样动态更改 imageView 的大小:-

  1. 您需要知道原始图像的比例。
  2. 然后使用以下代码计算屏幕的宽度:-

请看下面的代码:

    public static int getScreenWidth(Context mContext) {
            DisplayMetrics metrics = new DisplayMetrics();
            ((Activity) 
     mContext).getWindowManager().getDefaultDisplay().getMetrics(metrics);
            return metrics.widthPixels;
        }

3.现在你必须像这样改变 imageView 的参数:-

 imageView.getLayoutParams().height = (int) (Utility.getScreenWidth(this) * "your ratio");

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    • 2011-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多