Android 我的搜索栏和文本视图超出了屏幕限制

Android 我的搜索栏和文本视图超出了屏幕限制,android,size,screen,Android,Size,Screen,所以,经过几天的尝试,我根本找不到解决办法,我已经在一个问题中提出了这个问题,但正如有人在那里对我说的,我没有很好地阐述我的问题 如何使我的简单应用程序在所有屏幕上看起来都很好,我有一些屏幕截图向您展示困扰我的问题: 当我在屏幕上的emulator上运行我的应用程序时:1440x2560:560dpi 5.5“看起来很好: 但是当我在480x800:hdpi 4“上运行它时,它看起来是这样的: 或者,如果我在下面设置了android:layout_=“@id/containerLayout”

所以,经过几天的尝试,我根本找不到解决办法,我已经在一个问题中提出了这个问题,但正如有人在那里对我说的,我没有很好地阐述我的问题

如何使我的简单应用程序在所有屏幕上看起来都很好,我有一些屏幕截图向您展示困扰我的问题:

当我在屏幕上的emulator上运行我的应用程序时:
1440x2560:560dpi 5.5“
看起来很好:

但是当我在
480x800:hdpi 4“
上运行它时,它看起来是这样的:

或者,如果我在下面设置了android:layout_=“@id/containerLayout”,我的搜索栏和上面的文本视图就会在屏幕外向下移动(我可以看到第一个搜索栏,其他搜索栏被推到“容器”可见部分的下方)

这是我的密码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    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/background"
    tools:context="com.myapp.MainActivity">

    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <RelativeLayout
            android:id="@+id/logoLayout"
            android:layout_width="match_parent"
            android:layout_height="110dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginEnd="10dp"
            android:layout_marginStart="10dp"
            tools:layout_editor_absoluteX="8dp"
            tools:layout_editor_absoluteY="8dp">

            <ImageView
                android:id="@+id/logo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/logo"/>

        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/containerLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/buttonsLayout"
            android:layout_below="@+id/logoLayout"
            android:layout_marginEnd="10dp"
            android:layout_marginStart="10dp"
            android:background="@drawable/container">

            <LinearLayout
                android:id="@+id/layoutSaDataText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/tutorialImage"
                android:layout_alignParentTop="true"
                android:layout_margin="20dp"
                android:gravity="top"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/datatext1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:textAllCaps="false"
                    android:textColor="@color/whiteDark"
                    android:textSize="19sp"
                    android:textStyle="italic"/>

                <TextView
                    android:id="@+id/datatext3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:textAllCaps="false"
                    android:textColor="@color/whiteDark"
                    android:textSize="16sp"/>

                <TextView
                    android:id="@+id/datatext2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:textAllCaps="false"
                    android:textColor="@color/whiteDark"
                    android:textSize="16sp"/>

                <TextView
                    android:id="@+id/datatext4"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:textAllCaps="false"
                    android:textColor="@color/whiteDark"
                    android:textSize="16sp"/>

                <TextView
                    android:id="@+id/datatext5"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:textAllCaps="false"
                    android:textColor="@color/whiteDark"
                    android:textSize="16sp"/>

            </LinearLayout>

            <ImageView
                android:id="@+id/tutorialImage"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/logoLayout"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="70dp"
                android:layout_marginTop="25dp"
                app:srcCompat="@drawable/usagetutorial"
                tools:ignore="NotSibling"/>

            <ProgressBar
                android:id="@+id/loadingbar"
                style="?android:attr/progressBarStyle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:indeterminate="true"
                android:indeterminateTint="@color/progressBar"
                android:indeterminateTintMode="src_atop"
                />

            <LinearLayout
                android:id="@+id/layoutSaSeekerima"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_marginBottom="25dp"
                android:layout_marginEnd="25dp"
                android:layout_marginStart="25dp"
                android:gravity="bottom"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/playerLvlSeekerText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="15dp"
                    android:gravity="center"
                    android:text="data 1"
                    android:visibility="gone"/>

                <SeekBar
                    android:id="@+id/playerLvlSeeker"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="7dp"
                    android:max="250"
                    android:visibility="gone"/>


                <TextView
                    android:id="@+id/townHallLvlSeekerText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="15dp"
                    android:gravity="center"
                    android:text="data 2"
                    android:visibility="gone"/>

                <SeekBar
                    android:id="@+id/townHallLvlSeeker"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="7dp"
                    android:max="11"
                    android:visibility="gone"/>

                <TextView
                    android:id="@+id/trophiesCountSeekerText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="15dp"
                    android:gravity="center"
                    android:text="data 3"
                    android:visibility="gone"/>

                <SeekBar
                    android:id="@+id/trophiesCountSeeker"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="7dp"
                    android:max="100"
                    android:visibility="gone"/>

                <TextView
                    android:id="@+id/warStarsWonSeekerText"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="15dp"
                    android:gravity="center"
                    android:text="data 4"
                    android:visibility="gone"/>

                <SeekBar
                    android:id="@+id/warStarsWonSeeker"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="7dp"
                    android:max="100"
                    android:visibility="gone"/>
            </LinearLayout>

            <RelativeLayout
                android:id="@+id/usernameInputLayout"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_alignParentBottom="true"
                android:layout_marginEnd="25dp"
                android:layout_marginStart="25dp">

                <TextView
                    android:id="@+id/playertagbelow"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_centerInParent="false"
                    android:layout_centerVertical="false"
                    android:text="insert your data below"
                    android:textAllCaps="true"
                    android:textColor="@android:color/darker_gray"/>

                <EditText
                    android:id="@+id/usernameInput"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:layout_centerInParent="false"
                    android:layout_centerVertical="false"
                    android:ems="10"
                    android:hint="82VPLR89"
                    android:inputType="textPersonName"/>

            </RelativeLayout>
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/buttonsLayout"
            android:layout_width="match_parent"
            android:layout_height="90dp"
            android:layout_alignParentBottom="true"
            >

            <Button
                android:id="@+id/button2"
                android:layout_width="200dp"
                android:layout_height="70dp"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_centerInParent="false"
                android:layout_marginBottom="15dp"

                android:backgroundTint="@android:color/holo_green_dark"
                android:elevation="0dp"
                android:text="proceed"
                android:textSize="19sp"/>

            <Button
                android:id="@+id/button1"
                android:layout_width="200dp"
                android:layout_height="70dp"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:layout_centerInParent="false"
                android:layout_marginBottom="15dp"

                android:backgroundTint="@android:color/holo_green_dark"
                android:elevation="0dp"
                android:text="verify user"
                android:textSize="17sp"/>
        </RelativeLayout>

    </RelativeLayout>
</android.support.constraint.ConstraintLayout>

是否有一个解决方案,使我的搜索栏和一切大小根据屏幕大小,或唯一的解决方案是使每个屏幕(小,正常,大)分开布局

我花了好几天的时间试图弄明白这一点,我根本没有使用像素,一切都是dp和数学内容/家长。。但问题依然存在


谢谢转发!很抱歉代码太长,而且不是最好的英文:)

您是否正确设置了布局文件夹,例如布局、小布局、布局和大布局??”


下面是一个示例

删除您拥有的所有布局(约束布局除外),并使用以下各项将所有内容放置到位:

    android:layout_width="0dp"
    android:layout_height="0dp"

以及适当的限制(+边距)

因此,经过几天又几天的尝试,我意外地找到了解决方案。。 但这是最好的学习方法:D

解决方案是为文本视图设置布局权重,并在线性布局中正确地搜索条

android:layout_weight="1"
并将线性布局重心置于中心位置

android:gravity="center"

我的对象(文本视图和搜索栏)不再离开屏幕,它们只是适当地调整大小以适应布局/屏幕

我想这可能会解决你的问题。我没有,因为我几天前问了一个问题:那些家伙告诉我,我可能做得太多了,我需要在不做单独布局的情况下让它看起来不错。。所以我在这里再次问,有没有办法不做小/正常/大/XLarge等等。。对我来说,为每种屏幕大小制作布局并不难,只是我认为这可能是错误的解决方案,有一种方法可以在没有布局文件夹的情况下进行更正。没有其他方法可以在没有布局文件夹的情况下进行,密度像素也不起作用,只是在所有需要不同文件夹的设备上看起来都不合适,而且在每个设备上都会调整大小。