这里以体育运动的场馆为实例吧
import java.util.ArrayList;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.util.FloatMath;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
public class SSView extends View {
Context mContext;
int x_offset = 0;
/** 普通状态 */
private Bitmap mBitMapSeatNormal = null;
/** 已锁定 */
private Bitmap mBitMapSeatLock = null;
/** 已选中 */
private Bitmap mBitMapSeatChecked = null;
/** 缩略图画布 */
private Canvas mCanvas = null;
/** 是否显示缩略图 */
private boolean U = false;
/** 每个座位的高度 - 57 */
private int ss_seat_current_height = 57;
/** 每个座位的宽度 */
private int ss_seat_current_width = 57;
/** 座位之间的间距 */
private int L = 5;
private double T = 1.0D;
private double t = -1.0D;
private double u = 1.0D;
/** 是否可缩放 */
private boolean v = false;
/** 座位最小高度 */
private int ss_seat_min_height = 0;
/** 座位最大高度 */
private int ss_seat_max_height = 0;
/** 座位最小宽度 */
private int ss_seat_min_width = 0;
/** 座位最大宽度 */
private int ss_seat_max_width = 0;
private OnSeatClickListener mOnSeatClickListener = null;
public static double a = 1.0E-006D;
private int ss_between_offset = 2;
private int ss_seat_check_size = 50;
private int ss_seat_thum_size_w = 120;
private int ss_seat_thum_size_h = 90;
private int ss_seat_rect_line = 2;
/** 选座缩略图 */
private Bitmap mBitMapThumView = null;
/** 左边距 */
private int h = 0;
/** 右边距 */
private int i = 0;
/** 上边距 */
private int j = 80;
/** 下边距 */
private int k = 0;
/** 排数x轴偏移量 */
private float n = 0.0F;
/** 排数y轴偏移量 */
private float o = 0.0F;
/** 座位距离排数的距离 */
private int p = 0;
/** 可视座位距离顶端的距离 */
private int q = 0;
/** 整个view的宽度 */
private int r = 0;
/** 整个view的高度 */
private int s = 0;
/** 能否移动 */
private boolean w = true;
private boolean first_load_bg = true;
private int tempX;
private int tempY;
GestureDetector mGestureDetector = new GestureDetector(mContext,
new GestureListener(this));
private ArrayList<SeatInfo> mListSeatInfos = null;//行信息
private ArrayList<ArrayList<Integer>> mListSeatConditions = null;//是否预定了的信息
private int iMaxPay = 0;
private int totalCountEachRow;//列数据
private int rows;//行数据
public SSView(Context paramContext, AttributeSet paramAttributeSet) {
this(paramContext, paramAttributeSet, 0);
}
public SSView(Context paramContext, AttributeSet paramAttributeSet,
int paramInt) {
super(paramContext, paramAttributeSet, paramInt);
this.mContext = paramContext;
}
public void init(int row_count, int rows,
ArrayList<SeatInfo> list_seatInfos,
ArrayList<ArrayList<Integer>> list_seat_condtions,
int imaxPay) {
this.iMaxPay = imaxPay;
this.totalCountEachRow = row_count;
this.rows = rows;
this.mListSeatInfos = list_seatInfos;
this.mListSeatConditions = list_seat_condtions;
this.mBitMapSeatNormal = getBitmapFromDrawable((BitmapDrawable) this.mContext
.getResources().getDrawable(R.drawable.seat_normal));
this.mBitMapSeatLock = getBitmapFromDrawable((BitmapDrawable) this.mContext
.getResources().getDrawable(R.drawable.seat_lock));
this.mBitMapSeatChecked = getBitmapFromDrawable((BitmapDrawable) this.mContext
.getResources().getDrawable(R.drawable.seat_checked));
this.ss_seat_thum_size_w = this.mContext.getResources()
.getDimensionPixelSize(R.dimen.ss_seat_thum_size_w);
this.ss_seat_thum_size_h = this.mContext.getResources()
.getDimensionPixelSize(R.dimen.ss_seat_thum_size_h);
this.ss_seat_max_height = this.mContext.getResources()
.getDimensionPixelSize(R.dimen.seat_max_height);
this.ss_seat_max_width = this.mContext.getResources()
.getDimensionPixelSize(R.dimen.seat_max_width);
this.ss_seat_min_height = this.mContext.getResources()
.getDimensionPixelSize(R.dimen.seat_min_height);
this.ss_seat_min_width = this.mContext.getResources()
.getDimensionPixelSize(R.dimen.seat_min_width);
this.ss_seat_current_height = this.mContext.getResources()
.getDimensionPixelSize(R.dimen.seat_init_height);
this.ss_seat_current_width = this.mContext.getResources()
.getDimensionPixelSize(R.dimen.seat_init_width);
this.ss_seat_check_size = this.mContext.getResources()
.getDimensionPixelSize(R.dimen.ss_seat_check_size);//30dp
this.ss_between_offset = this.mContext.getResources()
.getDimensionPixelSize(R.dimen.ss_between_offset);//5dp
invalidate();
}
public static Bitmap getBitmapFromDrawable(
BitmapDrawable paramBitmapDrawable) {
return paramBitmapDrawable.getBitmap();
}
/**
*
* @param seatNum
* 每排的座位顺序号
* @param rowNum
* 排号
* @param paramBitmap
* @param paramCanvas1
* @param paramCanvas2
* @param paramPaint
*/
private void a(int seatNum, int rowNum, Bitmap paramBitmap,
Canvas paramCanvas1, Canvas paramCanvas2, Paint paramPaint) {
if (paramBitmap == null) {// 走道
paramCanvas1.drawRect(c(seatNum, rowNum), paramPaint);
if (this.U) {
paramCanvas2.drawRect(d(seatNum, rowNum), paramPaint);
}
} else {
paramCanvas1.drawBitmap(paramBitmap, null, c(seatNum, rowNum),
paramPaint);
if (this.U) {
paramCanvas2.drawBitmap(paramBitmap, null, d(seatNum, rowNum),
paramPaint);
}
paramPaint.setTextSize(0.3F * this.ss_seat_current_height);
paramCanvas1.drawText("30¥", c(seatNum, rowNum).centerX(), c(seatNum, rowNum).centerY() + 20, paramPaint);
}
}
/**
*
* @param seatNum
* 每排的座位号
* @param rowNum
* 排号
* @return
*/
private Rect c(int seatNum, int rowNum) {
try {
Rect localRect = new Rect(this.h + seatNum * this.ss_seat_current_width + this.L,
this.j + rowNum * this.ss_seat_current_height + this.L, this.h + (seatNum + 1)
* this.ss_seat_current_width - this.L, this.j + (rowNum + 1) * this.ss_seat_current_height
- this.L);
return localRect;
} catch (Exception localException) {
localException.printStackTrace();
}
return new Rect();
}
private Rect d(int seatNum, int rowNum) {
try {
Rect localRect = new Rect(
5 + (int) (this.T * (this.h + seatNum * this.ss_seat_current_width + this.L)),
5 + (int) (this.T * (this.j + rowNum * this.ss_seat_current_height + this.L)),
5 + (int) (this.T * (this.h + (seatNum + 1) * this.ss_seat_current_width - this.L)),
5 + (int) (this.T * (this.j + (rowNum + 1) * this.ss_seat_current_height - this.L)));
return localRect;
} catch (Exception localException) {
localException.printStackTrace();
}
return new Rect();
}
private Rect e(int paramInt1, int paramInt2) {
int i1;
int i3;
try {
if (getMeasuredWidth() < this.r) {
i1 = getMeasuredWidth();
} else {
i1 = this.r;
}
if (getMeasuredHeight() < this.s) {
i3 = getMeasuredHeight();
} else {
i3 = this.s;
}
return new Rect((int) (5.0D + this.T * paramInt1),
(int) (5.0D + this.T * paramInt2), (int) (5.0D + this.T
* paramInt1 + i1 * this.T), (int) (5.0D + this.T
* paramInt2 + i3 * this.T));
} catch (Exception e) {
e.printStackTrace();
return new Rect();
}
}
@Override
protected void onDraw(Canvas paramCanvas) {
super.onDraw(paramCanvas);
if (this.totalCountEachRow == 0 || this.rows == 0) {
return;
}
if (this.n + this.r < 0.0f || this.o + this.s < 0.0f) {
this.n = 0.0f;
this.o = 0.0f;
this.p = 0;
this.q = 0;
}
Paint localPaint2 = new Paint();
if (this.ss_seat_current_width != 0 && this.ss_seat_current_height != 0) {
this.mBitMapThumView = Bitmap.createBitmap(this.ss_seat_thum_size_w,
this.ss_seat_thum_size_h, Bitmap.Config.ARGB_8888);
this.mCanvas = new Canvas();
this.mCanvas.setBitmap(this.mBitMapThumView);
this.mCanvas.save();
Paint localPaint1 = new Paint();
localPaint1.setXfermode(new PorterDuffXfermode(
PorterDuff.Mode.CLEAR));
this.mCanvas.drawPaint(localPaint1);
double d1 = (this.ss_seat_thum_size_w - 10.0D)
/ (this.ss_seat_current_width * this.totalCountEachRow + this.h + this.i);
double d2 = (this.ss_seat_thum_size_h - 10.0D)
/ (this.ss_seat_current_height * this.rows);
if (d1 <= d2) {
this.T = d1;
} else {
this.T = d2;
}
if(this.U){
localPaint2.setColor(-16777216);
if(first_load_bg){
first_load_bg = false;
tempX = 5+(int) (this.r * this.T);
tempY = 5 + (int) (this.s * this.T);
}
this.mCanvas.drawRect(5.0F, 5.0F, tempX ,
tempY, localPaint2);
}
}
paramCanvas.translate(this.n, this.o);
this.r = this.h + this.ss_seat_current_width * this.totalCountEachRow + this.i;
this.s = this.ss_seat_current_height * this.rows + this.j;
this.h = (int) Math.round(this.ss_seat_current_width);
localPaint2.setTextAlign(Paint.Align.CENTER);
localPaint2.setAntiAlias(true);
localPaint2.setColor(-16777216);
for (int i2 = 0; i2 < this.mListSeatConditions.size(); i2++) {
ArrayList<Integer> localArrayList = (ArrayList<Integer>) this.mListSeatConditions
.get(i2);
for (int i3 = 0; i3 < this.mListSeatInfos.get(i2).getSeatList()
.size(); i3++) {
switch (((Integer) localArrayList.get(i3)).intValue()) { // 2373
case 0: // 2401 - 走道
localPaint2.setColor(0);
a(i3, i2, null, paramCanvas, this.mCanvas, localPaint2);
localPaint2.setColor(-16777216);
break;
case 1:// 可选
a(i3, i2, this.mBitMapSeatNormal, paramCanvas,
this.mCanvas, localPaint2);
break;
case 2://
a(i3, i2, this.mBitMapSeatLock, paramCanvas,
this.mCanvas, localPaint2);
break;
case 3: // 2500-一已点击的状态
a(i3, i2, this.mBitMapSeatChecked, paramCanvas,
this.mCanvas, localPaint2);
break;
default:
break;
}
}
// cond_d - 2538
}
// 画排数
localPaint2.setTextSize(0.3F * this.ss_seat_current_height);
for (int i1 = 0; i1 < this.mListSeatInfos.size(); i1++) {
localPaint2.setColor(-1308622848);
paramCanvas
.drawText( ((SeatInfo) this.mListSeatInfos.get(i1)).getDesc()
, (int) Math.abs(this.n) + this.ss_seat_current_width / 2
, this.j + i1 * this.ss_seat_current_height + this.ss_seat_current_height / 2 + this.k / 2 + 20
, localPaint2);
}
// 画列数
localPaint2.setTextSize(0.3F * this.ss_seat_current_height);
for (int x1 = 0; x1 < this.totalCountEachRow; x1++) {
localPaint2.setColor(-1308622848);
paramCanvas
.drawText(
String.valueOf(x1 + 1) + "号场"
,this.h + x1 * this.ss_seat_current_width + this.ss_seat_current_width / 2
, (int) Math.abs(this.o) + this.ss_seat_current_height / 3
, localPaint2);
}
if (this.U) {
// 画缩略图的黄色框
localPaint2.setColor(-739328);
localPaint2.setStyle(Paint.Style.STROKE);
localPaint2.setStrokeWidth(this.ss_seat_rect_line);
this.mCanvas.drawRect(
e((int) Math.abs(this.n), (int) Math.abs(this.o)),
localPaint2);
localPaint2.setStyle(Paint.Style.FILL);
this.mCanvas.restore();
}
}
public void setXOffset(int x_offset) {
this.x_offset = x_offset;
}
/**
* 获取两点的直线距离
*
* @param paramMotionEvent
* @return
*/
private float getTwoPoiniterDistance(MotionEvent paramMotionEvent) {
float f1 = paramMotionEvent.getX(0) - paramMotionEvent.getX(1);
float f2 = paramMotionEvent.getY(0) - paramMotionEvent.getY(1);
return FloatMath.sqrt(f1 * f1 + f2 * f2);
}
private void a(MotionEvent paramMotionEvent) {
double d1 = getTwoPoiniterDistance(paramMotionEvent);
if (this.t < 0.0D) {
this.t = d1;
} else {
try {
this.u = (d1 / this.t);
this.t = d1;
if ((this.v) && (Math.round(this.u * this.ss_seat_current_width) > 0L)
&& (Math.round(this.u * this.ss_seat_current_height) > 0L)) {
this.ss_seat_current_width = (int) Math.round(this.u * this.ss_seat_current_width);
this.ss_seat_current_height = (int) Math.round(this.u * this.ss_seat_current_height);
this.h = (int) Math.round(this.ss_seat_current_width);
this.i = this.h;
this.L = (int) Math.round(this.u * this.L);
if (this.L <= 0)
this.L = 1;
}
invalidate();
} catch (Exception localException) {
localException.printStackTrace();
}
}
}
/**
* new added
*
* @param mSsView
* @return
*/
public static float w(SSView mSsView) {
return mSsView.o;
}
/**
* 获取排数x轴偏移量
*
* @param mSsView
* @return
*/
public static float v(SSView mSsView) {
return mSsView.n;
}
/**
* 获取整个view的高度
*
* @param mSsView
* @return
*/
public static int u(SSView mSsView) {
return mSsView.s;
}
/**
* 获取可视座位距离顶端的距离
*
* @param mSsView
* @return
*/
public static int t(SSView mSsView) {
return mSsView.q;
}
/**
* 获取整个view的宽度
*
* @param mSsView
* @return
*/
public static int s(SSView mSsView) {
return mSsView.r;
}
/**
* 获取座位距离排数的横向距离
*
* @param mSsView
* @return
*/
public static int r(SSView mSsView) {
return mSsView.p;
}
/**
* 修改可见座位距离顶端的距离
*
* @param mSsView
* @return
*/
public static int l(SSView mSsView, int paramInt) {
mSsView.q = mSsView.q + paramInt;
return mSsView.q;
}
/**
* new added
*
* @param mSsView
* @param paramInt
* @return
*/
public static int k(SSView mSsView, int paramInt) {
mSsView.p = mSsView.p + paramInt;
return mSsView.p;
}
/**
* 设置可视座位距离顶端的距离
*
* @param mSsView
* @param paramInt
* @return
*/
public static int j(SSView mSsView, int paramInt) {
mSsView.q = paramInt;
return mSsView.q;
}
/**
* 设置座位距离排数的横向距离
*
* @param mSsView
* @return
*/
public static int i(SSView mSsView, int paramInt) {
mSsView.p = paramInt;
return mSsView.p;
}
/**
* new added
*
* @param mSsView
* @param param
* @return
*/
public static boolean a(SSView mSsView, boolean param) {
mSsView.U = param;
return mSsView.U;
}
/**
* 设置排数x轴偏移量
*
* @param mSsView
* @param param
* @return
*/
public static float a(SSView mSsView, float param) {
mSsView.n = param;
return mSsView.n;
}
/**
* 计算是第几列
*
* @param mSsView
* @param param
* @return
*/
public static int a(SSView mSsView, int param) {
return mSsView.a(param);
}
/**
* 计算是第几列
*
* @param paramInt
* @return
*/
private int a(int paramInt) {
try {
int i1 = (paramInt + this.p - this.h) / this.ss_seat_current_width;
return i1;
} catch (Exception localException) {
localException.printStackTrace();
}
return -1;
}
/**
* 是否可以移动和点击
*
* @param mSsView
* @return
*/
public static boolean a(SSView mSsView) {
return mSsView.w;
}
private int b() {
return (int) Math.round(this.ss_seat_current_width / this.ss_seat_check_size
* this.ss_between_offset);
}
/**
* 修改排数x轴的
*
* @param mSsView
* @param param
* @return
*/
public static float c(SSView mSsView, float param) {
mSsView.n = mSsView.n - param;
return mSsView.n;
}
/**
* 修改排数y轴的偏移量
*
* @param mSsView
* @param param
* @return
*/
public static float d(SSView mSsView, float param) {
mSsView.o = mSsView.o - param;
return mSsView.o;
}
/**
* new added
*
* @param mSsView
* @return
*/
public static OnSeatClickListener d(SSView mSsView) {
return mSsView.mOnSeatClickListener;
}
/**
* 设置排数y轴偏移量
*
* @param mSsView
* @param param
* @return
*/
public static float b(SSView mSsView, float param) {
mSsView.o = param;
return mSsView.o;
}
/**
* 计算是第几排
*
* @param mSsView
* @param param
* @return
*/
public static int b(SSView mSsView, int param) {
return mSsView.b(param);
}
/**
* new added
*
* @param mSsView
* @return
*/
public static ArrayList b(SSView mSsView) {
return mSsView.mListSeatConditions;
}
/**
* 计算是第几排
*
* @param paramInt
* @return
*/
private int b(int paramInt) {
try {
int i1 = (paramInt + this.q - this.j) / this.ss_seat_current_height;
return i1;
} catch (Exception localException) {
localException.printStackTrace();
}
return -1;
}
/**
* 设置按钮点击事件
*
* @param paramOnSeatClickLinstener
*/
public void setOnSeatClickListener(
OnSeatClickListener paramOnSeatClickLinstener) {
this.mOnSeatClickListener = paramOnSeatClickLinstener;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (event.getPointerCount() == 1) {
if (this.v) {
this.v = false;
this.w = false;
this.t = -1.0D;
this.u = 1.0D;
}else{
this.w = true;
}
while (this.ss_seat_current_width < this.ss_seat_min_width || this.ss_seat_current_height < this.ss_seat_min_height) {
this.ss_seat_current_width++;
this.ss_seat_current_height++;
this.h = (int) Math.round(this.ss_seat_current_width);
this.i = this.h;
this.L = b();
// 滑到最左和最上
SSView.i(this, 0);
SSView.a(this, 0.0F);
SSView.j(this, 0);
SSView.b(this, 0.0F);
invalidate();
}
while ((this.ss_seat_current_width > this.ss_seat_max_width) || (this.ss_seat_current_height > this.ss_seat_max_height)) {
this.ss_seat_current_width--;
this.ss_seat_current_height--;
this.h = (int) Math.round(this.ss_seat_current_width);
this.i = this.h;
this.L = b();
invalidate();
}
// 移动功能-点击事件
this.mGestureDetector.onTouchEvent(event);
}
return true;
}
}
public class OrderSelectActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener {
private static final int ROW = 14;
private static final int EACH_ROW_COUNT = 20;
private SSView mSSView;
private ArrayList<SeatInfo> list_seatInfos = new ArrayList<SeatInfo>();
private ArrayList<ArrayList<Integer>> list_seat_conditions = new ArrayList<ArrayList<Integer>>();
private ArrayList<String> timeList = new ArrayList<String>();
private ArrayList<Seat> seatList = new ArrayList<Seat>();
private RadioGroup mRadioGroup;
private RadioButton mRadioButton1;
private RadioButton mRadioButton2;
private RadioButton mRadioButton3;
private RadioButton mRadioButton4;
private RadioButton mRadioButton5;
private RadioButton mRadioButton6;
private RadioButton mRadioButton7;
private ImageView mImageView;
private TextView submitBtn;
private float mCurrentCheckedRadioLeft;//当前被选中的RadioButton距离左侧的距离
private HorizontalScrollView mHorizontalScrollView;//上面的水平滚动控件
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.order_select);
iniController();
iniListener();
initSelect();
initOrder();
initCommit(null);
}
private void iniListener() {
// TODO Auto-generated method stub
mRadioGroup.setOnCheckedChangeListener(this);
}
private void iniController() {
// TODO Auto-generated method stub
mRadioGroup = (RadioGroup)findViewById(R.id.radioGroup);
mRadioButton1 = (RadioButton)findViewById(R.id.btn1);
mRadioButton2 = (RadioButton)findViewById(R.id.btn2);
mRadioButton3 = (RadioButton)findViewById(R.id.btn3);
mRadioButton4 = (RadioButton)findViewById(R.id.btn4);
mRadioButton5 = (RadioButton)findViewById(R.id.btn5);
mRadioButton6 = (RadioButton)findViewById(R.id.btn6);
mRadioButton7 = (RadioButton)findViewById(R.id.btn7);
mImageView = (ImageView)findViewById(R.id.img1);
mHorizontalScrollView = (HorizontalScrollView)findViewById(R.id.horizontalScrollView);
mRadioButton1.setChecked(true);
mCurrentCheckedRadioLeft = getCurrentCheckedRadioLeft();
submitBtn = (TextView)findViewById(R.id.order_btn);
submitBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Utils.start_Activity(OrderSelectActivity.this, OrderActivity.class, null);
}
});
}
/**
* 获得当前被选中的RadioButton距离左侧的距离
*/
private float getCurrentCheckedRadioLeft() {
// TODO Auto-generated method stub
if (mRadioButton1.isChecked()) {
return getResources().getDimension(R.dimen.rdo1);
}else if (mRadioButton2.isChecked()) {
return getResources().getDimension(R.dimen.rdo2);
}else if (mRadioButton3.isChecked()) {
return getResources().getDimension(R.dimen.rdo3);
}else if (mRadioButton4.isChecked()) {
return getResources().getDimension(R.dimen.rdo4);
}else if (mRadioButton5.isChecked()) {
return getResources().getDimension(R.dimen.rdo5);
}else if (mRadioButton6.isChecked()) {
return getResources().getDimension(R.dimen.rdo6);
}else if (mRadioButton7.isChecked()) {
return getResources().getDimension(R.dimen.rdo7);
}
return 0f;
}
private void initCommit(String content)
{
TextView commit = (TextView)findViewById(R.id.order_btn);
if(null != content)
{
commit.setText(content);
}
}
private void initOrder()
{
MoveLayout moveLayout=(MoveLayout)findViewById(R.id.moveLayout);
MoveAdapter adapter=new MoveAdapter(this,seatList);
moveLayout.setAdapter(adapter);
}
private void initSelect(){
mSSView = (SSView)this.findViewById(R.id.mSSView);
setSeatInfo();
mSSView.init(EACH_ROW_COUNT, ROW, list_seatInfos, list_seat_conditions, 5);
mSSView.setOnSeatClickListener(new OnSeatClickListener() {
@Override
public boolean b(int column_num, int row_num, boolean paramBoolean) {
Seat seat = new Seat();
seat.setColumnNum(column_num);
seat.setRowNum(row_num);
seatList.add(seat);
initOrder();
initCommit((30 * seatList.size()) + "元" + " 提交订单");
return false;
}
@Override
public boolean a(int column_num, int row_num, boolean paramBoolean) {
ArrayList<Seat> seatListTemp = new ArrayList<Seat>();
for(Seat mSeat : seatList)
{
if(mSeat.getColumnNum() == column_num && mSeat.getRowNum() == row_num)
{
}else
{
seatListTemp.add(mSeat);
}
}
seatList.clear();
seatList.addAll(seatListTemp);
initOrder();
if(seatList.size() > 0)
{
initCommit((30 * seatList.size()) + "元" + " 提交订单" );
}else
{
initCommit("选择场地");
}
return false;
}
});
}
private void setSeatInfo(){
timeList.add("09:00");
timeList.add("10:00");
timeList.add("11:00");
timeList.add("12:00");
timeList.add("13:00");
timeList.add("14:00");
timeList.add("15:00");
timeList.add("16:00");
timeList.add("17:00");
timeList.add("18:00");
timeList.add("19:00");
timeList.add("20:00");
timeList.add("21:00");
timeList.add("22:00");
for(int i =0;i<ROW;i++){
SeatInfo mSeatInfo = new SeatInfo();
ArrayList<Seat> mSeatList = new ArrayList<Seat>();
ArrayList<Integer> mConditionList = new ArrayList<Integer>();
for(int j=0;j<EACH_ROW_COUNT;j++){
Seat mSeat = new Seat();
mConditionList.add(1);//这里说明,如果为0则表示空出布局位置,如果为1则为可以预定的场地,如果为2则表示已经被预定的场地
mSeatList.add(mSeat);
}
mSeatInfo.setDesc(timeList.get(i));
mSeatInfo.setRow(String.valueOf(i+1));
mSeatInfo.setSeatList(mSeatList);
list_seatInfos.add(mSeatInfo);
list_seat_conditions.add(mConditionList);
}
}
/**
* RadioGroup点击CheckedChanged监听
*/
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
AnimationSet _AnimationSet = new AnimationSet(true);
TranslateAnimation _TranslateAnimation;
if (checkedId == R.id.btn1) {
_TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo1), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(false);
_AnimationSet.setFillAfter(true);
_AnimationSet.setDuration(100);
mImageView.startAnimation(_AnimationSet);//开始上面蓝色横条图片的动画切换
}else if (checkedId == R.id.btn2) {
_TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo2), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(false);
_AnimationSet.setFillAfter(true);
_AnimationSet.setDuration(100);
mImageView.startAnimation(_AnimationSet);
}else if (checkedId == R.id.btn3) {
_TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo3), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(false);
_AnimationSet.setFillAfter(true);
_AnimationSet.setDuration(100);
mImageView.startAnimation(_AnimationSet);
}else if (checkedId == R.id.btn4) {
_TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo4), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(false);
_AnimationSet.setFillAfter(true);
_AnimationSet.setDuration(100);
mImageView.startAnimation(_AnimationSet);
}else if (checkedId == R.id.btn5) {
_TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo5), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(false);
_AnimationSet.setFillAfter(true);
_AnimationSet.setDuration(100);
mImageView.startAnimation(_AnimationSet);
}else if (checkedId == R.id.btn6) {
_TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo6), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(false);
_AnimationSet.setFillAfter(true);
_AnimationSet.setDuration(100);
mImageView.startAnimation(_AnimationSet);
}else if (checkedId == R.id.btn7) {
_TranslateAnimation = new TranslateAnimation(mCurrentCheckedRadioLeft, getResources().getDimension(R.dimen.rdo7), 0f, 0f);
_AnimationSet.addAnimation(_TranslateAnimation);
_AnimationSet.setFillBefore(false);
_AnimationSet.setFillAfter(true);
_AnimationSet.setDuration(100);
mImageView.startAnimation(_AnimationSet);
}
mCurrentCheckedRadioLeft = getCurrentCheckedRadioLeft();//更新当前蓝色横条距离左边的距离
mHorizontalScrollView.smoothScrollTo((int)mCurrentCheckedRadioLeft-(int)getResources().getDimension(R.dimen.rdo2), 0);
}
}
import java.util.ArrayList;
public class SeatInfo
{
private String row = null;
private String desc = null;
private ArrayList<Seat> mSeatList = null;
private String c(String paramString)
{
if (paramString == null)
paramString = "";
return paramString;
}
public Seat getSeat(int paramInt)
{
if ((paramInt > this.mSeatList.size()) || (paramInt < 0))
return new Seat();
return (Seat)this.mSeatList.get(paramInt);
}
public String getDesc()
{
return c(this.desc);
}
public void addSeat(Seat paramSeat)
{
this.mSeatList.add(paramSeat);
}
public void setRow(String paramString)
{
this.row = paramString;
}
public ArrayList getSeatList()
{
return this.mSeatList;
}
public void setSeatList(ArrayList<Seat> seat_list){
this.mSeatList = seat_list;
}
public void setDesc(String paramString)
{
this.desc = paramString;
}
}
@SuppressLint("NewApi")
public class MoveLayout extends LinearLayout {
private MoveAdapter adapter;
private Context context;
public MoveLayout(Context context, AttributeSet attrs) {
super(context, attrs);
this.context=context;
}
@SuppressLint("NewApi")
public void setAdapter(MoveAdapter adapter) {
this.adapter = adapter;
this.removeAllViews();
for(int i=0;i<adapter.getCount();i++){
View view=adapter.getView(i, null, null);
view.setPadding(10, 10, 10, 10);
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
this.setOrientation(HORIZONTAL);
this.addView(view,new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
}
}
}
public class MoveAdapter extends BaseAdapter {
private ArrayList<Seat> seatList = null;
private LayoutInflater inflater;
private Context context;
public MoveAdapter(Context context,ArrayList<Seat> seatList){
this.context=context;
this.seatList = seatList;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return seatList.size();
}
@Override
public Seat getItem(int location) {
return seatList.get(location);
}
@Override
public long getItemId(int arg0) {
return arg0;
}
@Override
public View getView(int location, View view, ViewGroup arg2) {
if (view == null) {
view = inflater.inflate(R.layout.move, null);
new ViewHolder(view);
}
ViewHolder holder = (ViewHolder) view.getTag();
Seat seat = getItem(location);
holder.time_interval.setText(seat.getTimeInterval());
holder.number_field.setText(seat.getField());
return view;
}
class ViewHolder {
TextView time_interval;
TextView number_field;
public ViewHolder(View view) {
time_interval = (TextView) view.findViewById(R.id.time_interval);
number_field = (TextView) view.findViewById(R.id.number_field);
view.setTag(this);
}
}
}
public class Seat
{
private ArrayList<String> timeList = null;
private ArrayList<String> fieldList = null;
public Seat()
{
initTimeData();
initFieldData();
}
private int row_num = 0;
private int price = 0;
private int column_num = 0;
public int getRowNum() {
return row_num;
}
public void setRowNum(int row_num) {
this.row_num = row_num;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getColumnNum() {
return column_num;
}
public void setColumnNum(int column_num) {
this.column_num = column_num;
}
public String getTimeInterval() {
return timeList.get(row_num);
}
public String getField()
{
return fieldList.get(column_num);
}
private void initFieldData()
{
fieldList = new ArrayList<String>();
fieldList.add("1号场");
fieldList.add("2号场");
fieldList.add("3号场");
fieldList.add("4号场");
fieldList.add("5号场");
fieldList.add("6号场");
fieldList.add("7号场");
fieldList.add("8号场");
fieldList.add("9号场");
fieldList.add("10号场");
fieldList.add("11号场");
fieldList.add("12号场");
fieldList.add("13号场");
fieldList.add("14号场");
fieldList.add("15号场");
fieldList.add("16号场");
fieldList.add("17号场");
fieldList.add("18号场");
fieldList.add("19号场");
fieldList.add("20号场");
}
private void initTimeData()
{
timeList = new ArrayList<String>();
timeList.add("09:00-10:00");
timeList.add("10:00-11:00");
timeList.add("11:00-12:00");
timeList.add("12:00-13:00");
timeList.add("13:00-14:00");
timeList.add("14:00-15:00");
timeList.add("15:00-16:00");
timeList.add("16:00-17:00");
timeList.add("17:00-18:00");
timeList.add("18:00-19:00");
timeList.add("19:00-20:00");
timeList.add("20:00-21:00");
timeList.add("21:00-22:00");
timeList.add("22:00-23:00");
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/id_venue_introduce_title"
android:name="com.upmi.sport.activity.fragment.OrderSelectTitleFragment"
android:layout_width="fill_parent"
android:layout_height="50dp" />
<LinearLayout
android:id="@+id/week"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#555555"
android:scrollbars="none">
<RelativeLayout
android:id="@+id/ll_week"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#33b5e5">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:orientation="horizontal">
<RadioButton
android:id="@+id/btn1"
style="@style/radioButton"
android:text="星期一" />
<RadioButton
android:id="@+id/btn2"
style="@style/radioButton"
android:text="星期二" />
<RadioButton
android:id="@+id/btn3"
style="@style/radioButton"
android:text="星期三" />
<RadioButton
android:id="@+id/btn4"
style="@style/radioButton"
android:text="星期四" />
<RadioButton
android:id="@+id/btn5"
style="@style/radioButton"
android:text="星期五" />
<RadioButton
android:id="@+id/btn6"
style="@style/radioButton"
android:text="星期六" />
<RadioButton
android:id="@+id/btn7"
style="@style/radioButton"
android:text="星期日" />
</RadioGroup>
<ImageView
android:id="@+id/img1"
android:layout_width="100dp"
android:layout_height="4dp"
android:layout_alignParentBottom="true"
android:background="#33b5e5" />
</RelativeLayout>
</HorizontalScrollView>
</LinearLayout>
<com.sport.activity.view.seatchoose.SSView
android:id="@+id/mSSView"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp" />
<RelativeLayout
android:id="@+id/order"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:scrollbars="none">
<com.sport.activity.view.MoveLayout
android:id="@+id/moveLayout"
android:layout_width="wrap_content"
android:layout_height="50dp" />
</HorizontalScrollView>
<TextView
android:id="@+id/order_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="6dp"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="6dp"
android:background="@drawable/btn_order_commit_selector"
android:gravity="center"
android:text="选择场地" />
</RelativeLayout>
</LinearLayout>