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

时间:2018-06-12 09:28:22

标签: 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.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>

enter image description here

4 个答案:

答案 0 :(得分:1)

试试这个

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

答案 1 :(得分:1)

试试这个:

<?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>

答案 2 :(得分:0)

<?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:orientation="vertical"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />


            </LinearLayout>
        </ScrollView>

答案 3 :(得分:0)

试试这个

    <?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>
相关问题