Подтвердить что ты не робот

Не может прокручивать ViewPager при касании TextView (с помощью android: gravity = "center" ) в нем

В моем ViewPager существовал ImageButton и TextView, удерживаемый LinearLayout, и теперь я меняю их на один TextView с возможностью переноса.

<?xml version="1.0" encoding="utf-8"?>
<com.iclinux.android.custom_views.NoScrollTextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:iclinux="http://schemas.android.com/apk/res-auto"
    android:clipChildren="false"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:singleLine="true"
    android:gravity="center"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:drawableTop="@drawable/icon_bg"
    style="@style/EllipsizedSingleLineTextView"
    android:textSize="@dimen/grid_item_title_size"
    >
</com.iclinux.android.custom_views.NoScrollTextView>

Мой вопрос: я не могу щелкнуть влево или вправо при касании TextView, но если удалить "android: gravity =" center ", он работает... к сожалению, текст не центрирован в любом случае...

public class NoScrollTextView extends TextView {

    public NoScrollTextView(Context context) {
        super(context);
    }

    public NoScrollTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NoScrollTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_MOVE)
            return false;
        return super.onTouchEvent(event);
    }
}

Что здесь произошло? Большое спасибо.

4b9b3361

Ответ 1

android:singleLine="true" заставляет android:scrollHorizontally установить значение true, и согласно моим тестам, только если вы измените android:gravity ( т.е. гравитация по умолчанию, похоже, не дает этой проблемы).

Я решил эту проблему в TextView, просто заменив android:singleLine="true" на android:maxLines="1"

После этого изменения у меня не было больше проблем с ViewPager. Теперь он прокручивается, как ожидалось, при касании элементов с помощью android:gravity="right".

Ответ 2

решаются путем переопределения:

@TargetApi(14)
@Override
public boolean canScrollHorizontally(int direction) {
    return false;
}

Ответ 3

Я сделал это, выполнив:

textView.setHorizontallyScrolling(false);