как сделать кнопку нельзя прокручивать - PullRequest
0 голосов
/ 08 июня 2018

я хочу, чтобы мою кнопку нельзя было здесь прокрутить.так что кнопка просто остается на кнопке, когда я прокручиваю ее вверх или вниз.я пытаюсь сделать прокрутку за пределами кнопки, но кнопка не появляется.и я также попытался сделать кнопку внутри scrollview, но кнопка стала прокручиваемой.я хочу, чтобы кнопка оставалась на кнопке и не прокручивалась.

это мой код

<LinearLayout 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="#f1f1f1"
    android:orientation="vertical"
    tools:context=".Activity.TambahLaporActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

    <android.support.v7.widget.CardView
        android:id="@+id/cv"
        android:layout_width="match_parent"
        android:layout_height="180dp"
        android:foreground="?android:attr/selectableItemBackground">

        <ImageView
            android:id="@+id/tambah"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:src="@drawable/add" />
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp">

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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:text="Lokasi dan Jenis"
                android:textColor="@android:color/black"
                android:textSize="20dp" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@color/colorPrimary"/>

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="Gedung : "
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

                <TextView
                    android:id="@+id/gedung"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="gedung"
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

            </LinearLayout>

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="Ruangan : "
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

                <TextView
                    android:id="@+id/ruang"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="ruang"
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

            </LinearLayout>

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="Pada : "
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

                <TextView
                    android:id="@+id/tanggal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="tanggal"
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text=" yang lalu"
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

            </LinearLayout>

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="Aset : "
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

                <TextView
                    android:id="@+id/aset"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="aset"
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

            </LinearLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:text="Keterangan"
                android:textColor="@android:color/black"
                android:textSize="20dp" />

            <TextView
                android:id="@+id/keterangan"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:text="ket"
                android:textColor="@android:color/black"
                android:textSize="15dp" />
        </LinearLayout>
    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp">

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

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:text="Lokasi dan Jenis"
                android:textColor="@android:color/black"
                android:textSize="20dp" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@color/colorPrimary"/>

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="Gedung : "
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

                <TextView
                    android:id="@+id/gedung"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="gedung"
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

            </LinearLayout>

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="Ruangan : "
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

                <TextView
                    android:id="@+id/ruang"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="ruang"
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

            </LinearLayout>

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="Pada : "
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

                <TextView
                    android:id="@+id/tanggal"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="tanggal"
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text=" yang lalu"
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

            </LinearLayout>

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="Aset : "
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

                <TextView
                    android:id="@+id/aset"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:text="aset"
                    android:textColor="@android:color/black"
                    android:textSize="15dp" />

            </LinearLayout>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:text="Keterangan"
                android:textColor="@android:color/black"
                android:textSize="20dp" />

            <TextView
                android:id="@+id/keterangan"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:text="ket"
                android:textColor="@android:color/black"
                android:textSize="15dp" />
        </LinearLayout>
    </android.support.v7.widget.CardView>
        </LinearLayout>
    </ScrollView>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@color/colorPrimary"
            android:text="Cancel"
            android:textColor="@android:color/white" />
    </RelativeLayout>

</LinearLayout>

как сделать так, чтобы кнопка существовала, а не прокручивалась при прокрутке макета вверх или вниз?спасибо

Ответы [ 2 ]

0 голосов
/ 08 июня 2018

Вам нужно включить Scrollview в RelativeLayout вашей кнопки

<RelativeLayout>
    <ScrollView>
        .......
    <Scrollview/>
    <Button/>
<RelativeLayout/>
0 голосов
/ 08 июня 2018

Попробуйте этот код, он работает нормально, поместите то, что вы хотите, внутри вашего LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".Activity.TambahLaporActivity">

    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@color/colorPrimary"
        android:text="Cancel"
        android:textColor="@android:color/white" />

    <ScrollView
        android:id="@+id/sv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/btn">

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



        </LinearLayout>

    </ScrollView>

</RelativeLayout>
...