Android: RealViewSwitcher don't scrolling in vertical - android

im using RealViewSwitcher to swipe view and it's ok, my problem is similar to this one. i will try to explain a bit my scenario by this pic
listview <------> detail view ------> swipe view (horizontal).
The detail view is showing only partially and if try to scroll nothing happens.
Detail layout (no vertical scrolling)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColorHint="#FF0000"
android:textSize="12dp"
android:textStyle="bold"
android:typeface="sans" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="150dip"
android:layout_height="120dip"
android:scaleType="centerCrop"
android:src="#drawable/stub"/>
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="20dip"
android:textColor="#999999"
android:textColorLink="#ff0000"
android:textSize="20dip"
android:textStyle="normal"
android:typeface="sans" />
</LinearLayout>
layout with RealViewSwitcher
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical">
<it.application.ppn.lib.RealViewSwitcher
android:id="#+id/horizontal_pager"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1">
</it.application.ppn.lib.RealViewSwitcher>
</LinearLayout>

I faced with the same problem and found solution by intercepting touch event in RealViewSwitcher.
EDIT: previous posted variant does not work on newer API. There is third revision of code.
Add those lines into RealViewSwitcher implementation:
#Override
public boolean onInterceptTouchEvent(MotionEvent event) {
// prevent vertical scrolling when view switching in progress
if (!mScroller.isFinished())
return true;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mScrollLocked = false;
mLastX = event.getX();
mLastY = event.getY();
mDeltaX = 0;
mDeltaY = 0;
onTouchEvent(event);
break;
case MotionEvent.ACTION_MOVE:
final float x = event.getX();
final float y = event.getY();
mDeltaX += Math.abs(x - mLastX);
mDeltaY += Math.abs(y - mLastY);
mLastX = x;
mLastY = y;
if (mDeltaX > mDeltaY) {
mScrollLocked = true;
onTouchEvent(event);
} else {
snapToDestination();
}
break;
}
if (mScrollLocked)
return true; // prevent furhter processing
return super.onInterceptTouchEvent(event);
}
EDIT2: also need to edit onTouchEvent method and replace case MotionEvent.ACTION_DOWN: body as follows:
case MotionEvent.ACTION_DOWN:
/*
* If being flinged and user touches, stop the fling. isFinished will be false if being flinged.
*/
mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
if (mTouchState == TOUCH_STATE_SCROLLING) {
mScroller.abortAnimation();
}
// Remember where the motion event started
mLastMotionX = x;
break;

Related

Android: Horizontal and vertical scroll for recyclerview

I am trying to implement horizontal and vertical scrolling for a Recycler view at the same time.I have to show a table of 8 columns, so I plan to implement horizontal and vertical scrolling at the same time.
I tried HorizontalScrollView in list row but it is scrolling horizontally in one row.
I also tried the HorizontalScrollView as the parent of recyclerview but its not working
list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:clickable="true"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">
<TextView
android:id="#+id/title"
android:textColor="#color/title"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaa"/>
<TextView
android:layout_toRightOf="#+id/title"
android:id="#+id/genre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="bbb"/>
<TextView
android:layout_toRightOf="#+id/genre"
android:id="#+id/year"
android:textColor="#color/year"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="20dp"
android:layout_height="wrap_content"
android:text="ccc"/>
</RelativeLayout>
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal" >
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
can any one please tell me an idea.
The best solution i found so far to have horizontal and vertical scrolling on one view is to put it inside one FrameLayout. Then your view must implement OnTouch (you can do this in your activity to) and you just have to scroll it as the touch pointer moves.
Here is an example :
xml :
<FrameLayout
android:id="#+id/TwoWaysScrollableContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false">
<YourView
android:id="#+id/GridContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false" />
</FrameLayout>
C# (i use xamarin, but Java wouldn't have so many differencies i think)
:
public class MyActivity : Activity
{
private MyView _myView; //Can be GridView, relative layout or wathever
private float _startX, _startY,_prevDx, _prevDy, _dx,_dy;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
_myView = FindViewById<MyView>(Resource.Id.GridContainer);
}
public bool OnTouch(View v, MotionEvent e)
{
switch (e.Action)
{
case MotionEventActions.Down:
{
mode = Mode.DRAG;
startX = e.GetX() - prevDx;
startY = e.GetY() - prevDy;
break;
}
case MotionEventActions.Move:
{
/* you also could add logic to prevent your view from scrolling out of you grid bounds*/
if (mode == Mode.DRAG)
{
dx = startX - e.GetX();
dy = startY - e.GetY();
_myView.ScrollBy((int)(dx), (int)(dy));
startX = e.GetX();
startY = e.GetY();
}
break;
}
case MotionEventActions.Up:
{
mode = Mode.NONE;
prevDx = dx;
prevDy = dy;
break;
}
}
return true;
}
}
I know this doesn't answer your question directly ( i don't know much about recycler view), but i hope it can still help you. I used this for a tile engine and it did the trick very well.

How to set Image position relative to another Image on Android

I try to explain my problem. I have two ImageViews.
One of them is the background image and large as well.
This background image has also a zoom function. The other Image is a small image with size of 36x36.
The small image can be moved around the screen:
public boolean onTouch(View view, MotionEvent event) {
final int X = (int) event.getRawX();
final int Y = (int) event.getRawY();
//Definition MotionEvent.ACTION_MASK: Bit mask of the parts of the action code that are the action itself.
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
_xDelta = X - lParams.leftMargin;
_yDelta = Y - lParams.topMargin;
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view
.getLayoutParams();
layoutParams.leftMargin = X - _xDelta;
layoutParams.topMargin = Y - _yDelta;
layoutParams.rightMargin = -250;
layoutParams.bottomMargin = -250;
view.setLayoutParams(layoutParams);
break;
}
viewGroup.invalidate();
return true;
}
If i zoom in the background image, the small image doesn't zoom. It's position is absolute to the screen and not to the Image.
How can i make the small Image to be relative to the large Image?
I hope it's clear what my Problem is.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:id="#+id/root">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/skizze"
android:scaleType="matrix"
/>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:id="#+id/feuerloescher"
android:layout_gravity="center_horizontal|top"
android:layout_alignParentTop="false"
android:src="#drawable/feuerloescher"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="false" />
</RelativeLayout>
try with android:layout_below="#id/skizze"
Try as following xml code
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/skizze"
android:scaleType="matrix"
/>
<ImageView
android:layout_width="55dp"
android:layout_height="55dp"
android:id="#+id/feuerloescher"
android:layout_gravity="center_horizontal|top"
android:layout_alignParentTop="false"
android:src="#drawable/feuerloescher"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="false"
android:layout_below="#id/skizze" />
I know this is an old post however just in case it helps I just had this same issue and was able to resolve it as follows.
android:layout_alignTop="#id/app_bg_fill"
"alignTop" seemed to be the key line. Full code follows.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/app_bg_fill"
android:orientation="vertical" >
<ImageView
android:id="#+id/app_bg_fill"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="60dp"
android:layout_marginTop="100dp"
android:scaleType="fitEnd"
android:src="#drawable/guide_item_2f"
android:background="#drawable/view_frame_style" />
<TextView
android:layout_width="match_parent"
android:layout_height="100sp"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="20sp"
android:layout_marginRight="20sp"
android:layout_marginBottom="20sp"
android:background="#00000000"
android:layout_centerInParent="true"
android:padding="12sp"
android:text="SomeText"
android:layout_alignTop="#id/app_bg_fill"
android:textColor="#000000" />
</RelativeLayout>

Custom View does not move with gestures

I recently implemented the Dragging and Scaling code that was offered on the Android Developer website FOUND HERE
The problem I am running into is in regards to the ability to move the view once it has been added to a layout. The image is scalable through the gesture but not movable.
This view is being added to a FrameLayout that is within a Fragment if that helps at all.
Has anyone ran into a similar problem implementing this Android example in a custom view? or can someone tell me what I am missing that I cannot move the views that I am adding.
public class CustomImageView extends View {
private static final int INVALID_POINTER_ID = 0;
Drawable _drawable;
// private static readonly int InvalidPointerId = -1;
// private int _activePointerId = InvalidPointerId;
private float _posX;
private float _posY;
private float mScaleFactor = 1.0f;
private int mActivePointerId = INVALID_POINTER_ID;
// gesture listeners
private ScaleGestureDetector mScaleDetector;
private float mLastTouchX;
private float mLastTouchY;
private float mPosY;
private float mPosX;
public CustomImageView(Context context, int resourceId) {
super(context, null, 0);
_drawable = getResources().getDrawable(resourceId);
_drawable.setBounds(0, 0, 200, 200);
mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
// TODO Auto-generated constructor stub
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.save();
canvas.translate(_posX, _posY);
canvas.scale(mScaleFactor, mScaleFactor);
_drawable.draw(canvas);
canvas.restore();
}
#Override
public boolean onTouchEvent(MotionEvent ev) {
// Let the ScaleGestureDetector inspect all events.
mScaleDetector.onTouchEvent(ev);
final int action = MotionEventCompat.getActionMasked(ev);
switch (action) {
case MotionEvent.ACTION_DOWN: {
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final float x = MotionEventCompat.getX(ev, pointerIndex);
final float y = MotionEventCompat.getY(ev, pointerIndex);
// Remember where we started (for dragging)
mLastTouchX = x;
mLastTouchY = y;
// Save the ID of this pointer (for dragging)
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
break;
}
case MotionEvent.ACTION_MOVE: {
// Find the index of the active pointer and fetch its position
final int pointerIndex = MotionEventCompat.findPointerIndex(ev,
mActivePointerId);
final float x = MotionEventCompat.getX(ev, pointerIndex);
final float y = MotionEventCompat.getY(ev, pointerIndex);
// Calculate the distance moved
final float dx = x - mLastTouchX;
final float dy = y - mLastTouchY;
mPosX += dx;
mPosY += dy;
invalidate();
// Remember this touch position for the next move event
mLastTouchX = x;
mLastTouchY = y;
break;
}
case MotionEvent.ACTION_UP: {
mActivePointerId = INVALID_POINTER_ID;
break;
}
case MotionEvent.ACTION_CANCEL: {
mActivePointerId = INVALID_POINTER_ID;
break;
}
case MotionEvent.ACTION_POINTER_UP: {
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev,
pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mLastTouchX = MotionEventCompat.getX(ev, newPointerIndex);
mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex);
mActivePointerId = MotionEventCompat.getPointerId(ev,
newPointerIndex);
}
break;
}
}
return true;
}
private class ScaleListener extends
ScaleGestureDetector.SimpleOnScaleGestureListener {
#Override
public boolean onScale(ScaleGestureDetector detector) {
mScaleFactor *= detector.getScaleFactor();
// Don't let the object get too small or too large.
mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 5.0f));
invalidate();
return true;
}
}
}
Here is the XML, the root_layout that I am adding the views to is a FrameLayout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="#dimen/ab_height"
android:background="#color/red" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageButton
android:id="#+id/btn_Back"
android:layout_width="#dimen/width"
android:layout_height="fill_parent"
android:background="#color/red"
android:contentDescription="#string/desc"
android:src="#drawable/ic_navigation_back" />
<LinearLayout
android:layout_width="#dimen/dim_1"
android:layout_height="fill_parent"
android:background="#color/red" >
</LinearLayout>
<TextView
android:id="#+id/text_name"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:tag="bold"
android:text="Pixagram"
android:textColor="#color/white"
android:textSize="#dimen/tex_size_xxxlarge"
android:textStyle="bold" />
<LinearLayout
android:layout_width="#dimen/dim_1"
android:layout_height="fill_parent"
android:background="#color/red" >
</LinearLayout>
<ImageButton
android:id="#+id/btn_Accept"
android:layout_width="#dimen/width"
android:layout_height="fill_parent"
android:background="#color/red"
android:contentDescription="#string/desc"
android:src="#drawable/ic_navigation_accept" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="#dimen/dim_1"
android:background="#color/red" >
</LinearLayout>
<FrameLayout
android:id="#+id/root_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<ImageView
android:id="#+id/imageViewEdit"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/abc_ab_solid_dark_holo" />
</FrameLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#color/red"
android:orientation="horizontal" >
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:gravity="bottom"
android:background="#color/transparent" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="#color/transparent" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc_ic_clear" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc_tab_selected_pressed_holo" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc_ic_clear" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc_tab_selected_pressed_holo" />
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc_ic_clear" />
<ImageButton
android:id="#+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc_tab_selected_pressed_holo" />
<ImageButton
android:id="#+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc_ic_clear" />
<ImageButton
android:id="#+id/imageButton8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc_tab_selected_pressed_holo" />
<ImageButton
android:id="#+id/imageButton9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc_ic_clear" />
<ImageButton
android:id="#+id/imageButton10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/abc_tab_selected_pressed_holo" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
</LinearLayout>
This seems to show that ACTION_MOVE is not getting called
09-23 23:14:46.310: I/ViewRootImpl(24235): ViewRoot's Touch Event : Touch Down
09-23 23:14:46.350: I/ViewRootImpl(24235): ViewRoot's Touch Event : Touch UP
09-23 23:14:47.300: I/ViewRootImpl(24235): ViewRoot's Touch Event : Touch Down
09-23 23:14:47.790: I/ViewRootImpl(24235): ViewRoot's Touch Event : Touch UP
09-23 23:14:48.000: I/ViewRootImpl(24235): ViewRoot's Touch Event : Touch Down
09-23 23:14:48.030: I/ViewRootImpl(24235): ViewRoot's Touch Event :261
09-23 23:14:48.670: I/ViewRootImpl(24235): ViewRoot's Touch Event :6
09-23 23:14:48.710: I/ViewRootImpl(24235): ViewRoot's Touch Event : Touch UP
09-23 23:14:48.980: I/ViewRootImpl(24235): ViewRoot's Touch Event : Touch Down
09-23 23:14:49.320: I/ViewRootImpl(24235): ViewRoot's Touch Event : Touch UP
Although I haven't dug carefully through all of your code, it looks like that in your onDraw() method, you are translating by _posX and _posY, but you don't change these anywhere in your gesture handling. Try using mPosX and mPosY in onDraw() instead.

Gallery View inside scroll view not working.

I'm using gallery view inside scoll view but gallery view not working properly.
My custom GalleryView
<com.divum.Adapter.CustomGallery
android:id="#+id/gallery"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none"
android:spacing="10dp" />
Adapter Layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/top_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="2dp"
android:orientation="vertical"
android:weightSum="100">
<TextView
android:id="#+id/txt_title1"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:padding="5dp"
android:textColor="#color/black"
android:textSize="14dp" />
<ImageView
android:id="#+id/image1"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:layout_marginTop="2dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:layout_marginLeft="2dp" />
<ScrollView
android:scrollHorizontally="false"
android:fadingEdge="none"
android:scrollbars="none"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/txt_details"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:padding="5dp"
android:textColor="#color/black"
android:textSize="14dp" />
</ScrollView>
</LinearLayout>
My problem is scrollview(vertically) working fine. The galleryview(horizontally) swiping is not working...
This is well known bug: ScrollView intercept both horizontal and vertical touch events. You can use this custom scroll view instead of standard one. This intercept only vertical touches:
public class VerticalScrollView extends ScrollView {
private float xDistance, yDistance, lastX, lastY;
public VerticalScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
lastX = ev.getX();
lastY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
xDistance += Math.abs(curX - lastX);
yDistance += Math.abs(curY - lastY);
lastX = curX;
lastY = curY;
if (xDistance > yDistance)
return false;
}
return super.onInterceptTouchEvent(ev);
}
}

SlidingDrawer with RadioButtons as Handle

I have a custom draggable SlidingDrawer using RadioButtons as its Handle. In order to enable the touch events on the RadioButtons I call return super.onInterceptTouchEvent(event); instead of return true on the onInterceptTouchEvent method. But somehow every time I want to drag my SlidingDrawer I can't drag it up by touching exactly on the RadioButtons, I have to move my finger up a little bit to drag the SlidingDrawer up.
Is there any way to make the SlidingDrawer exactly draggable by touching its RadioButtons without losing the TouchEvent on the RadioButtons itself?
Here's my touch method:
public boolean onInterceptTouchEvent(MotionEvent event) {
if (mLocked) {
//return false;
}
final int action = event.getAction();
float x = event.getX();
float y = event.getY();
final Rect frame = mFrame;
final View handle = mHandle;
handle.getHitRect(frame);
if (!mTracking && !frame.contains((int) x, (int) y)) {
return false;
}
if (action == MotionEvent.ACTION_DOWN) {
mTracking = true;
WWHApplication.getListActivityIntance().resizeListView(1800);
handle.setPressed(true);
// Must be called before prepareTracking()
prepareContent();
// Must be called after prepareContent()
if (mOnDrawerScrollListener != null) {
mOnDrawerScrollListener.onScrollStarted();
}
if (mVertical) {
final int top = mHandle.getTop();
mTouchDelta = (int) y - top;
prepareTracking(top);
} else {
final int left = mHandle.getLeft();
mTouchDelta = (int) x - left;
prepareTracking(left);
}
mVelocityTracker.addMovement(event);
}
//return true;
return super.onInterceptTouchEvent(event);
}
Here's how my handle looks like
<LinearLayout
android:id="#+id/handle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/tab_content_bg_top" />
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/tab_content_bg"
android:fillViewport="true"
android:scrollbars="none" >
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/cb_tab_all"
android:layout_width="46dp"
android:layout_height="45dp"
android:background="#drawable/checkbox_background"
android:button="#drawable/tab_all_selector"
android:onClick="true" />
<RadioButton
android:id="#+id/cb_tab_favorites"
android:layout_width="84dp"
android:layout_height="45dp"
android:background="#drawable/checkbox_background"
android:button="#drawable/tab_favorites_selector"
android:onClick="true" />
<RadioButton
android:id="#+id/cb_tab_historical"
android:layout_width="134dp"
android:layout_height="45dp"
android:background="#drawable/checkbox_background"
android:button="#drawable/tab_historical_selector"
android:onClick="true" />
<RadioButton
android:id="#+id/cb_tab_food"
android:layout_width="116dp"
android:layout_height="45dp"
android:background="#drawable/checkbox_background"
android:button="#drawable/tab_food_selector"
android:onClick="true" />
</RadioGroup>
</HorizontalScrollView>
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/tab_content_bg_bottom" />
</LinearLayout>

Categories

Resources