In my ViewPager, there was a ImageButton and TextView hold by LinearLayout, and now I change them to one TextView with coupound drawable.
<?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>
My question is: I can not flip left or right when touching the TextView, but if removed "android:gravity="center", it works... unfortunately, the text is not centered anyway...
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);
}
}
What happened here? thanks a lot.
The ViewPager is populated with fragments taking up space way beyond the screen (vertically). Still, nothing on the screen is scrollable.
You can't use ViewPager to swipe between Activities . You need to convert each of you five Activities into Fragments , then combine everything in one FragmentActivity with the Adapter you use with ViewPager .
ViewPager is a layout manager that allows the user to flip left and right through pages of data. It is mostly found in apps like Youtube, Snapchat where the user shifts right – left to switch to a screen. Instead of using activities fragments are used.
solved by overriding:
@TargetApi(14)
@Override
public boolean canScrollHorizontally(int direction) {
return false;
}
android:singleLine="true"
forces android:scrollHorizontally
to be set to true, and according to my tests only if you change android:gravity
(i.e. default gravity seems not to give this problem).
I solved this issue in a TextView by simply replacing android:singleLine="true"
with android:maxLines="1"
After this change, I had no more problems with the ViewPager. Now it is scrolling as expected while touching elements with android:gravity="right"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With