Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何解决不同屏幕上的应用程序显示问题?_Java_Android_Xml - Fatal编程技术网

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

Java 如何解决不同屏幕上的应用程序显示问题?,java,android,xml,Java,Android,Xml,为什么我的应用程序显示因设备而异 请帮助我在不同的设备(如图像)中从四面八方修复我的应用程序UI 我的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="htt

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

请帮助我在不同的设备(如图像)中从四面八方修复我的应用程序UI

我的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>

您可以使用下面的
weightSum
实现这一点

<?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"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="1">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="30dp"
        android:layout_weight=".2"
        app:srcCompat="@drawable/close_btn" />

    <TextView
        android:id="@+id/imageView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".4"
        android:background="@drawable/timer"
        android:gravity="center"
        android:text="15s"
        android:textColor="#3B3B3B"
        android:textSize="20dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".4"
        android:gravity="center"
        android:text="Score: 430"
        android:textColor="#000"
        android:textSize="18dp" />

</LinearLayout>


您只需使用RelativeLayout即可修复视图

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


添加xml代码@Laxminarayan DasI在这类情况下使用布局权重和权重之和添加了xml代码@yuvrajsinhstart。同样的结果,右侧仍在剪切@Yuvrajsinhre将此完整xml与您的xml放在一起?请检查它在我的两个屏幕@LaxminarayanDas中是否正常工作