Elackya
Elackya

Reputation: 119

Unable to add more than one button in Linear Layout

I use Linear Layout in my code and I want to add buttons in my activity using vertical scrollbar. But I'm not able to add more than one button in android. Drag and drop is not working and also manual xml coding doesn't work either. Please help

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

Upvotes: 0

Views: 57

Answers (4)

chandan
chandan

Reputation: 117

Try this

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

Upvotes: 0

Umair
Umair

Reputation: 6426

Try this:

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

Upvotes: 1

faran.javed
faran.javed

Reputation: 418

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

Upvotes: 0

Sandeep Parish
Sandeep Parish

Reputation: 2238

Try this

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>

Upvotes: 1

Related Questions