小编icl*_*nux的帖子

当触摸TextView(带有android:gravity ="center")时,无法滚动ViewPager

在我的ViewPager中,有一个由LinearLayout保持的ImageButton和TextView,现在我将它们改为一个带有coupound drawable的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>
Run Code Online (Sandbox Code Playgroud)

我的问题是:触摸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);
    }
}
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?非常感谢.

android textview

13
推荐指数
2
解决办法
2099
查看次数

标签 统计

android ×1

textview ×1