简体   繁体   English

为什么 Android 应用在某些手机上看起来不一样

[英]Why Android app looks different in some phones

I have an Android app that, in most phones it looks as want to.我有一个 Android 应用程序,在大多数手机中它看起来都想要。 Like this:像这样: 在此处输入图片说明

But in some phones, texts looks too big and everything looses proportions.但在某些手机中,文本看起来太大,一切都失去了比例。 Like this:像这样: 在此处输入图片说明

One of my xml file is this:我的 xml 文件之一是这样的:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="independent.dev.ui.Activities.WheelActivity"
    android:background="@drawable/wheel_background"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center_horizontal">

        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:background="@drawable/wheel_icon" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="25sp"
            android:text="Convertidor de graduación"
            android:layout_gravity="center"
            android:textColor="@color/white"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:gravity="center_horizontal"
        android:layout_marginHorizontal="30dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="vertical"
            android:gravity="center"
            android:layout_weight="1">

            <ImageView
                android:layout_width="100dp"
                android:layout_height="65dp"
                android:background="@drawable/isotype_green"
                android:layout_marginTop="50dp"
                android:layout_centerHorizontal="true"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:gravity="center_horizontal"
                android:layout_marginTop="50dp"
                android:layout_alignParentBottom="true">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="@string/wheelOriginalScale"
                    android:fontFamily="@font/helvetica"
                    android:textSize="24sp"
                    android:textColor="@color/white"
                    android:layout_weight="1"
                    android:textAlignment="center"/>

                <View
                    android:layout_width="2dp"
                    android:layout_height="match_parent"
                    android:background="@color/white"/>

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="@string/wheelGrades"
                    android:textAlignment="center"
                    android:fontFamily="@font/helveticabold"
                    android:textSize="28sp"
                    android:textColor="@color/white"
                    android:layout_weight="1"
                    android:layout_gravity="center"/>

                <View
                    android:layout_width="2dp"
                    android:layout_height="match_parent"
                    android:background="@color/white"/>

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:text="@string/wheelObjectiveScale"
                    android:textAlignment="center"
                    android:fontFamily="@font/helvetica"
                    android:textSize="24sp"
                    android:textColor="@color/white"
                    android:layout_weight="1"/>
            </LinearLayout>
        </RelativeLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="horizontal"
            android:gravity="center_vertical"
            android:layout_weight="0.8">

            <com.aigestudio.wheelpicker.WheelPicker
                android:id="@+id/wOriginalScale"
                android:layout_width="0dp"
                android:layout_height="180dp"
                android:layout_weight="1"
                android:fontFamily="@font/helveticabold"/>

            <com.aigestudio.wheelpicker.WheelPicker
                android:id="@+id/wGrades"
                android:layout_width="0dp"
                android:layout_height="180dp"
                android:layout_weight="1"
                android:fontFamily="@font/helveticabold"/>

            <com.aigestudio.wheelpicker.WheelPicker
                android:id="@+id/wObjectiveScale"
                android:layout_width="0dp"
                android:layout_height="180dp"
                android:layout_weight="1"
                android:fontFamily="@font/helveticabold"/>
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:orientation="horizontal"
            android:layout_weight="0.7">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:background="@drawable/view_border"
                android:paddingHorizontal="20dp"
                android:layout_gravity="center">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/helveticabold"
                    android:text="Resultado:  "
                    android:textColor="@color/appGreen"
                    android:textSize="30sp" />

                <TextView
                    android:id="@+id/tvResult"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="30sp"
                    android:text="5.4"
                    android:textColor="@color/white"/>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

I don't know why this happens.我不知道为什么会发生这种情况。 At the beginning of the app, in those phones that now looks weird, that app crashed because the images I'm using were too big so I created the "drawable-xxhdpi" folder, move pictures there, and now the app doesn't crashes but it looks like this.在应用程序开始时,在那些现在看起来很奇怪的手机中,该应用程序崩溃了,因为我使用的图像太大,所以我创建了“drawable-xxhdpi”文件夹,将图片移到那里,现在应用程序没有崩溃,但它看起来像这样。 Any ideas of what could be happening???关于可能发生什么的任何想法??? Many thanks!非常感谢!

for solve this problem you should be use ConstraintLayout instead of LinearLayout为了解决这个问题,你应该使用 ConstraintLayout 而不是 LinearLayout

please try to learn about Constraint layout and read below link请尝试了解约束布局并阅读以下链接

https://developer.android.com/training/multiscreen/screensizes https://developer.android.com/training/multiscreen/screensizes

Android App UI might look differently on different devices because the screen height and width of all android device are not the same. Android App UI 在不同设备上的外观可能会有所不同,因为所有 Android 设备的屏幕高度和宽度都不相同。 The App might look perfect on a Large Screen device and look bigger on a small screen device.该应用程序可能在大屏幕设备上看起来很完美,而在小屏幕设备上看起来更大。 To correct this error I somethings use layoutweight and weightsum to device my screen in a fixed ratio so that it maintain the same ratio in all devices.为了纠正这个错误,我使用 layoutweight 和 weightsum 以固定比例来设置我的屏幕,以便它在所有设备中保持相同的比例。 I also use sdp and ssp library to make my text and drawable have similar size in different device.我还使用 sdp 和 ssp 库使我的文本和可绘制对象在不同设备中具有相似的大小。

Here is a single layout built using sdp: sample of sdp layout这是使用 sdp 构建的单个布局: sdp 布局示例

Here is a sample of layout built using dp;这是使用 dp 构建的布局示例; sampe of the usual dp layout Check out this android library, it helps in giving adequate proportion of your layout in different devices.通常的 dp 布局示例查看这个 android 库,它有助于在不同设备中提供足够的布局比例。

https://github.com/intuit/sdp https://github.com/intuit/sdp

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

相关问题 为什么dp,px,mm在不同的Android手机中看起来不同 - Why dp, px, mm looks different in different android phones 为什么菜单项的背景图像在不同的手机上看起来不同? - Why do menu item background image looks different on different phones? Android绝对布局在某些手机上看起来不错,但在其他手机上却不行吗? - Android Absolute Layout looks good on some phones but not others? 小部件在不同手机上的外观不同 - Widget looks different on different phones Android:屏幕布局在相同型号的2部手机上看起来有所不同 - Android: Screen Layout looks different on 2 phones of the same model 为什么我的Android应用程序看起来从英语到西班牙语都不同? - Why does my Android app looks different from english to spanish? 应用程序在Android Market上发布,但在某些手机中不可见 - App is published in Android Market but not visible in some phones Android 应用程序无法在某些手机中启动 - Android app doesn't start in some phones 在PathClassLoader中的某些手机上无法加载Android应用 - Android app fails to load on some phones in PathClassLoader Android Studio:应用在某些手机上崩溃 - Android Studio: App crashes on some phones
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM