SwipeView类似桌面的滑动界面
使用了android 2.0以上的ExifInte易做图ce来生成缩略图。可用来设计游戏的选关界面。
Java代码
import uk.co.jasonfry.android.tools.ui.PageControl.OnPageControlClickListener;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
public class SwipeView extends HorizontalScrollView
{
private static int DEFAULT_SWIPE_THRESHOLD = 60;
private LinearLayout mLinearLayout;
private Context mContext;
private int SCREEN_WIDTH;
private int mMotionStartX;
private int mMotionStartY;
private boolean mMostlyScrollingInX = false;
private boolean mMostlyScrollingInY = false;
private boolean mJustInterceptedAndIgnored = false;
protected boolean mCallScrollToPageInOnLayout = false;
private int mCurrentPage = 0;
private int mPageWidth = 0;
private OnPageChangedListener mOnPageChangedListener = null;
private SwipeOnTouchListener mSwipeOnTouchListener;
private View.OnTouchListener mOnTouchListener;
private PageControl mPageControl = null;
/**
* {@inheritDoc}
*/
public SwipeView(Context context)
{
super(context);
mContext = context;
initSwipeView();
}
/**
* {@inheritDoc}
*/
public SwipeView(Context context, AttributeSet attrs)
{
super(context, attrs);
mContext = context;
initSwipeView();
}
/**
* {@inheritDoc}
*/
public SwipeView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs,defStyle);
mContext = context;
initSwipeView();
}
private void initSwipeView()
{
Log.i("uk.co.jasonfry.android.tools.ui.SwipeView","Initialising SwipeView");
mLinearLayout = new LinearLayout(mContext);
mLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
super.addView(mLinearLayout, -1, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
setSmoothScrollingEnabled(true);
setHorizontalFadingEdgeEnabled(false);
setHorizontalScrollBarEnabled(false);
Display display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
SCREEN_WIDTH = (int) (display.getWidth());
mPageWidth = SCREEN_WIDTH;
mCurrentPage = 0;
mSwipeOnTouchListener = new SwipeOnTouchListener();
super.setOnTouchListener(mSwipeOnTouchListener);
}
/**
* {@inheritDoc}
*/
@Override
public boolean onTrackballEvent(MotionEvent event)
{
return true;
}
@Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect)
{
//this will now pass trackball events down to onTrackballEvent
return false;
}
@Override
public void requestChildFocus(View child, View focused)
{
//this will now pass trackball events down to onRequestFocusInDescendants
requestFocus();
}
/**
* {@inheritDoc}
*/
@Override
public void addView(View child)
{
this.addView(child,-1);
}
/**
* {@inheritDoc}
*/
@Override
public void addView (View child, int index)
{
ViewGroup.LayoutParams params;
if(child.getLayoutParams()==null)
{
params = new LayoutParams(mPageWidth, LayoutParams.FILL_PARENT);
}
else
 
补充:移动开发 , Android ,