简体   繁体   English

截至 2019 年,使用现代技术支持不同的屏幕尺寸

[英]Supporting Different Screen Sizes With modern techniques as of 2019

This question has been asked more then 100 times on SO, for example this question was asked 8 years before.这个问题在 SO 上被问了超过 100 次,例如这个问题是在 8 年前被问到的。 And for sure the methods define in discussion are obsolete.并且可以肯定的是,讨论中定义的方法已经过时了。

With the new designing components such as Constraint Layout and changes in bucket such as MipMap and other changes in techniques I want to discuss now the modern techniques.随着新的设计组件(如约束布局)和桶的变化(如 MipMap)以及其他技术的变化,我现在想讨论现代技术。

What are the best practices for making an app to support large number of devices when it comes to designing specifically.在专门设计时,使应用程序支持大量设备的最佳实践是什么? I have more then 3 years of experience in android and still I am keen to learn the new things which are not generally discussed anywhere officially.我在 android 方面有超过 3 年的经验,但我仍然热衷于学习通常在任何地方都没有正式讨论过的新事物。 So can you tell me what rules must be followed to support different screen sizes?那么你能告诉我必须遵循什么规则来支持不同的屏幕尺寸吗?

For Example I am going to show you screen which we must look on all devices to look like same例如,我将向您展示我们必须在所有设备上看起来都一样的屏幕

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    android:layout_width="match_parent"    
    android:orientation="vertical"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_height="wrap_content"
    android:layout_margin="30dp"
    android:gravity="center"
    >

    <TextView
        android:id="@+id/lblLogo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="@string/app_name"
        android:autoSizeTextType="uniform"
        android:gravity="center"
        android:padding="15dp"
        />


    <!-- Email Label -->
    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/tilLoginEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/etLoginEmail"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textEmailAddress"
            android:hint="Email" />

    </com.google.android.material.textfield.TextInputLayout>



    <!-- Password Label -->
    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/tilLoginPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/etLoginPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            android:hint="Password"/>

    </com.google.android.material.textfield.TextInputLayout>



    <com.google.android.material.button.MaterialButton
        android:id="@+id/btnLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:padding="12dp"
        android:text="@string/btnLogin"/>
</LinearLayout>

This looks perfectly good on mobile devices, but looks worst on tablets and large screen.这在移动设备上看起来非常好,但在平板电脑和大屏幕上看起来最差。

see the picture below on mobile screen.请在手机屏幕上查看下图。

在此处输入图片说明

see the picture below on tablets在平板电脑上查看下图

在此处输入图片说明

Question: What what should be done to show centered beautiful layout in tablet too instead of wide full screen edit text.问题:应该怎么做才能在平板电脑中显示居中漂亮的布局,而不是全屏编辑文本。 In other words what should be followed to show layout same on all devices according to new techniques?换句话说,应该遵循什么来根据新技术在所有设备上显示相同的布局?

Note: I know if we apply some properties we can limit width of edittext in given example but we can not use such properties in other complex layouts.注意:我知道如果我们应用一些属性,我们可以在给定的示例中限制 edittext 的宽度,但我们不能在其他复杂布局中使用这些属性。

May be you can try below library which manages all the screen size resolution automatically.也许您可以尝试以下自动管理所有屏幕尺寸分辨率的库。 I am using this in my current projects.我在我当前的项目中使用它。

For Dimension对于维度

implementation 'com.intuit.sdp:sdp-android:1.0.6'

For TextSize对于文本大小

implementation 'com.intuit.ssp:ssp-android:1.0.6'

For More Info https://github.com/intuit/sdp更多信息https://github.com/intuit/sdp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM