0
scrollview2 = (ScrollView) findViewById(R.id.scrollview2);
    scrollview2.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            gonext();
        }});

Свойство clickable = true, но при нажатии в любую точку ScrollView ничего не происходит. Почему?

Пытался повесить тот же код на какой-либо из Layouts, но они в сравнении со ScrollView занимают куда меньше места на экране, а мне нужно сделать некое подобие any key.

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
    android:id="@+id/main_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="appname.body"
    android:paddingBottom="6dp"
    android:background="@drawable/body1"
    android:clickable="true"
    android:contextClickable="true">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:animationCache="true"
        android:fadeScrollbars="true"
        android:id="@+id/scrollview2"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:clipToPadding="false"
        android:layout_alignParentBottom="true"
        android:layout_marginTop="60dp"
        android:clickable="true">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/linear123"
            android:clickable="true">

            <TextView
                android:text="TextView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_marginLeft="19dp"
                android:layout_marginStart="19dp"
                android:layout_marginTop="39dp"
                android:id="@+id/textView2" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>
5
  • Покажите layout-файл.
    – post_zeew
    22 ноя 2016 в 15:42
  • Stackoverflow по какой-то причине убирает основной(родительский?) RelativeLayout. 22 ноя 2016 в 15:47
  • Код выделяется 4-мя пробелами. Если не получится – оставьте как есть, при этом код будет содержаться в сообщении, но может не отображаться, я сам его отформатирую.
    – post_zeew
    22 ноя 2016 в 15:56
  • Вроде залил. Посмотрите? 22 ноя 2016 в 16:10
  • Смотрите ответ.
    – post_zeew
    22 ноя 2016 в 17:29

1 ответ 1

5

Свойство clickable = true, но при нажатии в любую точку ScrollView ничего не происходит. Почему?

Потому что клики по ScrollView обрабатываются его дочерними элементами.

Для обработки кликов по ScrollView необходимо добавить в него любой ViewGroup, например, как у Вас – LinearLayout, растянуть его по всей площади ScrollView, задать ему атрибут android:clickable="true" и обрабатывать клики уже по этому ViewGroup.

Чтобы Ваш LinearLayout растягивался по всему ScrollView, к ScrollView необходимо добавить атрибут android:fillViewport="true".

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.