使用android studio时,线性布局未正确显示组件

使用android studio时,线性布局未正确显示组件,android,Android,这是密码 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent">

这是密码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:text="Email:"
        android:textSize="30dp"
        android:paddingLeft="0dp"
        android:paddingTop="10dp"/>

    <EditText
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        android:singleLine="true" />

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Login"
        android:paddingTop="10dp"/>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:text="Home" />

        <TextView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:text="About" />

    </LinearLayout>
</LinearLayout>
我想在androidstudio中练习布局,但在实现代码时遇到了一个错误。 这是移动屏幕外的文本:

为什么蓝色框会出现在手机屏幕之外

您可以自己设置每个视图的布局宽度。你应该知道有一个最大的屏幕宽度是可用的。此外,当相邻视图的宽度固定时,将按钮的宽度设置为match_parent是不正确的。如果您使用的是LinearLayout,请尝试“布局重量”属性。玩游戏,试着做实验

例如:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<TextView
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:paddingLeft="0dp"
    android:paddingTop="10dp"
    android:text="Email:"
    android:textSize="30dp" />

<EditText
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="4dp"
    android:layout_weight="2"
    android:singleLine="true" />

<Button
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:paddingTop="10dp"
    android:text="Login" />

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="100dp"
        android:text="Home" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="200dp"
        android:text="About" />

</LinearLayout>
</LinearLayout>

您没有正确设置布局。parentViewLinearLayout的子视图是水平对齐的,没有设置子视图。你应该看报纸。但是,要修复布局,可以添加另一个容器来保存布局的第一行,以使第二行在屏幕上可见。当前代码在一行中包含所有子视图,这使得其他视图不可见。请尝试以下代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <TextView
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:text="Email:"
            android:textSize="30dp"
            android:paddingLeft="0dp"
            android:paddingTop="10dp"/>

        <EditText
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:singleLine="true" />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Login"
            android:paddingTop="10dp"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_width="200dp"
            android:layout_height="100dp"
            android:text="Home" />

        <TextView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:text="About" />

     </LinearLayout>
</LinearLayout>

首先,您必须学习在android中创建设计的基础知识。无论何处,您都在硬编码视图的宽度和高度。如果不需要的话,你不应该硬编码宽度和高度。你不应该使用match_Parents。那么我使用的是什么,使组件位于屏幕内请仔细阅读我的答案。布局权重是选项之一,它允许您将视图以分数形式放置到屏幕上。Google itI将在我的答案中包含布局代码