【发布时间】:2013-05-30 16:25:12
【问题描述】:
在我的 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>
我的问题是:触摸 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);
}
}
这里发生了什么?非常感谢。
【问题讨论】:
-
我遇到的一个有趣的错误。谢谢你。我投了你一票。
-
同样的问题,找到答案here