-2
<?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"
android:orientation="vertical"
android:background="@mipmap/bg"
android:scrollbars="none"
android:weightSum="1">

<Button
    android:id="@+id/downbtn"
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_gravity="bottom|center_horizontal"
    android:layout_marginBottom="128dp"
    android:layout_marginEnd="19dp"
    android:background="@drawable/hand" />

<ScrollView
    android:id="@+id/QuesSix"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true">

    <LinearLayout
        android:id="@+id/layoutSix"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"

        android:paddingBottom="16dp"
        android:paddingLeft="16dp"
        android:paddingRight="16dp"
        android:paddingTop="16dp">

        <com.badoualy.stepperindicator.StepperIndicator
            android:id="@+id/stepper_indicator"
            android:layout_width="match_parent"

            android:layout_height="wrap_content"
            app:stpi_circleColor="#00b47c"
            app:stpi_stepCount="6" />


    </LinearLayout>


</ScrollView>


</RelativeLayout>

I have implemented a static button on a scroll view. But the button (id: downbtn) is not clickable. Even if I add a onClick Listener, nothing happens. What can I do to make the button click and have a click event? I tried all the blogs and nothing helped me.

  • Put the button inside a linearlayout. Check here https://stackoverflow.com/a/9326544/8604877 – Usman Sajad Mar 29 '18 at 17:23
  • Firstly your post title is misleading--The `Button` is above the `ScrollView` not on it. Secondly you have not shown how you have tried to implement the `onClick`. Please edit your post and provide the code where you are attempting to handle `onClick` – Barns Mar 29 '18 at 17:27
  • down.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { layou.scrollTo(0, layout.getBottom()); } }); – Jayadev Prasad Mar 29 '18 at 17:35
  • Add that to your post not in the comment. And we will need to know where you setup the `onClickListener`. For example in the `onCreate` method, are you defining everything properly. That is what we need to see, because obviously you are doing something wrong in your implementation. – Barns Mar 29 '18 at 17:59

1 Answers1

1

In RelativeLayout you have to specify rules for child Views .

In your case Button hide behind the other view so it can not take click .

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@mipmap/bg"
    >

    <Button
        android:id="@+id/downbtn"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="128dp"
        android:layout_marginEnd="19dp"
        android:background="@drawable/hand"
        />

    <ScrollView
        android:id="@+id/QuesSix"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/downbtn"
        >

        <LinearLayout
            android:id="@+id/layoutSix"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingBottom="16dp"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:paddingTop="16dp">
            <com.badoualy.stepperindicator.StepperIndicator
                android:id="@+id/stepper_indicator"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:stpi_circleColor="#00b47c"
                app:stpi_stepCount="6" />

        </LinearLayout>

    </ScrollView>
</RelativeLayout>

Also android:weightSum is useless in case of RelativeLayout . You might wanna have look at Layouts in android

ADM
  • 20,406
  • 11
  • 52
  • 83