Android 无法在线性布局中添加多个按钮

Android 无法在线性布局中添加多个按钮,android,android-layout,Android,Android Layout,我在代码中使用线性布局,我想使用垂直滚动条在活动中添加按钮。但我无法在android中添加多个按钮。拖放不起作用,手动xml编码也不起作用。请帮忙 activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.

我在代码中使用线性布局,我想使用垂直滚动条在活动中添加按钮。但我无法在android中添加多个按钮。拖放不起作用,手动xml编码也不起作用。请帮忙

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/chco"
    tools:context="com.example.tset.test.Prerequisites">

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

    </LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/chco"
    tools:context="com.example.tset.test.Prerequisites">

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

                    <Button
                        android:id="@+id/btnLogin"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Traveler Login" />

                    <Button
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:text="Login" />
                </LinearLayout>

</ScrollView>

试试这个

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
    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:orientation="vertical"
    android:gravity="center_vertical"
    android:background="@drawable/login_bg"
    tools:context=".activities.LoginActivity">
    <LinearLayout
        android:orientation="vertical"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/submit"
            android:textSize="18sp"
            android:text="Login"/> 
            <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/submit1"
            android:textSize="18sp"
            android:text="Login1"/> 
    </LinearLayout>

</ScrollView>
activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/chco"
    tools:context="com.example.tset.test.Prerequisites">

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

    </LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/chco"
    tools:context="com.example.tset.test.Prerequisites">

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

                    <Button
                        android:id="@+id/btnLogin"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Traveler Login" />

                    <Button
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:text="Login" />
                </LinearLayout>

</ScrollView>

试试这个

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
    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:orientation="vertical"
    android:gravity="center_vertical"
    android:background="@drawable/login_bg"
    tools:context=".activities.LoginActivity">
    <LinearLayout
        android:orientation="vertical"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/submit"
            android:textSize="18sp"
            android:text="Login"/> 
            <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/submit1"
            android:textSize="18sp"
            android:text="Login1"/> 
    </LinearLayout>

</ScrollView>
activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/chco"
    tools:context="com.example.tset.test.Prerequisites">

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

    </LinearLayout>
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/chco"
    tools:context="com.example.tset.test.Prerequisites">

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

                    <Button
                        android:id="@+id/btnLogin"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Traveler Login" />

                    <Button
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:text="Login" />
                </LinearLayout>

</ScrollView>



试试这个:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/chco"
tools:context="com.example.tset.test.Prerequisites"
android:fillViewport="true">

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


    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/chco"
tools:context="com.example.tset.test.Prerequisites"
android:fillViewport="true">

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


    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />
</LinearLayout>

试试这个

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
    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:orientation="vertical"
    android:gravity="center_vertical"
    android:background="@drawable/login_bg"
    tools:context=".activities.LoginActivity">
    <LinearLayout
        android:orientation="vertical"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/submit"
            android:textSize="18sp"
            android:text="Login"/> 
            <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/submit1"
            android:textSize="18sp"
            android:text="Login1"/> 
    </LinearLayout>

</ScrollView>

试试这个

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView
    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:orientation="vertical"
    android:gravity="center_vertical"
    android:background="@drawable/login_bg"
    tools:context=".activities.LoginActivity">
    <LinearLayout
        android:orientation="vertical"
        android:gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/submit"
            android:textSize="18sp"
            android:text="Login"/> 
            <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/submit1"
            android:textSize="18sp"
            android:text="Login1"/> 
    </LinearLayout>

</ScrollView>


您面临的真正问题是什么?我无法在活动中添加按钮。请检查我的答案:)请检查屏幕截图..我在android中使用了“匹配父项”:宽度。。我需要按钮来填充屏幕。。请帮助你面临的真正问题是什么?我无法在我的活动中添加按钮。请检查我的答案:)请检查屏幕截图..我对android使用了“匹配父项”:宽度。。我需要按钮来填充屏幕。。请帮忙,我试过了。请参考我上面的截图。按钮在屏幕上不合适。在左边aligned@Elackya请检查是否将其包装为内容,而不是使用匹配父项。就像我在回答中使用的一样谢谢。。它起作用了。。我纠正了线性布局标签下的android:layout\u width=“wrap\u content”,它成功了。Thanks@Elackya很乐意帮忙。快乐编码:)我试过了。请参考我上面的截图。按钮在屏幕上不合适。在左边aligned@Elackya请检查是否将其包装为内容,而不是使用匹配父项。就像我在回答中使用的一样谢谢。。它起作用了。。我纠正了线性布局标签下的android:layout\u width=“wrap\u content”,它成功了。Thanks@Elackya很乐意帮忙。快乐编码:)