如何解决应用在不同屏幕上的显示问题?

为什么我的应用程序显示因设备而异

这是我在某些设备中得到的输出

这是某些设备的输出,您可以清楚地看到右侧正在切割

请帮助我在不同的设备中从各个方面修复我的应用程序 UI,如图1所示。

我的 XML 代码

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

<RelativeLayout 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"

android:background="@drawable/bg_pic"

tools:context=".MainActivity">



<LinearLayout

    android:layout_width="match_parent"

    android:layout_height="wrap_content">


    <ImageView

        android:id="@+id/imageView"

        android:layout_width="33dp"

        android:layout_height="27dp"

        android:layout_marginLeft="15dp"

        android:layout_marginTop="10dp"

        app:srcCompat="@drawable/close_btn" />


        <LinearLayout

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_marginLeft="135dp"

            android:layout_marginTop="5dp"

            android:gravity="center">


            <TextView

                android:id="@+id/imageView2"

                android:layout_height="wrap_content"

                android:layout_width="wrap_content"

                android:background="@drawable/timer"

                android:gravity="center"

                android:text="15s"

                android:textSize="20dp"

                android:textColor="#3B3B3B"

                android:textStyle="bold" />

                </LinearLayout>


        <TextView

            android:id="@+id/textView"

            android:layout_width="97dp"

            android:layout_height="40dp"

            android:layout_marginLeft="80dp"

            android:layout_marginTop="10dp"

            android:gravity="center"

            android:text="Score: 430"

            android:textColor="#000"

            android:textSize="18dp" />


</LinearLayout>



</RelativeLayout>


慕娘9325324
浏览 96回答 2
2回答

慕哥6287543

你可以只用RelativeLayout来修复你的视图<?xml version="1.0" encoding="utf-8"?><RelativeLayout android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="match_parent"&nbsp; &nbsp; xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp; xmlns:app="http://schemas.android.com/apk/res-auto">&nbsp; &nbsp; <ImageView&nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/imageView"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="33dp"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="27dp"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_marginStart="16dp"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_marginTop="16dp"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_alignParentStart="true"&nbsp; &nbsp; &nbsp; &nbsp; app:srcCompat="@drawable/ic_round_close" />&nbsp; &nbsp; &nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_marginTop="16dp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/imageView2"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:background="@drawable/timer"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:layout_centerHorizontal="true"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:text="15s"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textSize="20sp"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textColor="#3B3B3B"&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android:textStyle="bold" />&nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; android:layout_alignParentEnd="true"&nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/textView"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_marginTop="16dp"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_marginEnd="16dp"&nbsp; &nbsp; &nbsp; &nbsp; android:gravity="center"&nbsp; &nbsp; &nbsp; &nbsp; android:text="Score: 430"&nbsp; &nbsp; &nbsp; &nbsp; android:textColor="#000"&nbsp; &nbsp; &nbsp; &nbsp; android:textSize="18sp" /></RelativeLayout>

蝴蝶不菲

weightSum您可以通过使用以下方法来实现此目的<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp; xmlns:app="http://schemas.android.com/apk/res-auto"&nbsp; &nbsp; android:layout_width="match_parent"&nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; android:orientation="horizontal"&nbsp; &nbsp; android:weightSum="1">&nbsp; &nbsp; <ImageView&nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/imageView"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="0dp"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="30dp"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_weight=".2"&nbsp; &nbsp; &nbsp; &nbsp; app:srcCompat="@drawable/close_btn" />&nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/imageView2"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="0dp"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_weight=".4"&nbsp; &nbsp; &nbsp; &nbsp; android:background="@drawable/timer"&nbsp; &nbsp; &nbsp; &nbsp; android:gravity="center"&nbsp; &nbsp; &nbsp; &nbsp; android:text="15s"&nbsp; &nbsp; &nbsp; &nbsp; android:textColor="#3B3B3B"&nbsp; &nbsp; &nbsp; &nbsp; android:textSize="20dp"&nbsp; &nbsp; &nbsp; &nbsp; android:textStyle="bold" />&nbsp; &nbsp; <TextView&nbsp; &nbsp; &nbsp; &nbsp; android:id="@+id/textView"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_width="0dp"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_height="wrap_content"&nbsp; &nbsp; &nbsp; &nbsp; android:layout_weight=".4"&nbsp; &nbsp; &nbsp; &nbsp; android:gravity="center"&nbsp; &nbsp; &nbsp; &nbsp; android:text="Score: 430"&nbsp; &nbsp; &nbsp; &nbsp; android:textColor="#000"&nbsp; &nbsp; &nbsp; &nbsp; android:textSize="18dp" /></LinearLayout>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java