自定义ViewFlipperTest
16lz
2021-01-26
package hyz.com.viewflipper;import android.app.Activity;import android.os.Bundle;public class ViewFlipperTestActivity extends Activity{@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.main);}}
package hyz.com.viewflipper;import android.content.Context;import android.util.AttributeSet;import android.view.GestureDetector.OnGestureListener;import android.view.animation.AnimationUtils;import android.view.GestureDetector;import android.view.LayoutInflater;import android.view.MotionEvent;import android.view.View;import android.widget.ViewFlipper;import android.view.View.OnTouchListener;public class MyViewFlipper extends ViewFlipper implements OnGestureListener,OnTouchListener{ private GestureDetector mGestureDetector; //private LayoutInflater inflater; private final Context mContext; public MyViewFlipper(Context context, AttributeSet attrs) {super(context, attrs);mContext = context;//addView(R.layout.silent);//addView(R.layout.on);mGestureDetector = new GestureDetector(this); setOnTouchListener(this); setLongClickable(true); } public MyViewFlipper(Context context) {super(context);mContext = context;}// private View addView(int layout) // {// inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);// View view = inflater.inflate(layout, null); // return view; // }@Overridepublic boolean onTouch(View v, MotionEvent event) {// TODO Auto-generated method stubreturn mGestureDetector.onTouchEvent(event);}@Overridepublic boolean onDown(MotionEvent e) {// TODO Auto-generated method stubreturn false;}@Overridepublic void onShowPress(MotionEvent e) {// TODO Auto-generated method stub}@Overridepublic boolean onSingleTapUp(MotionEvent e) {// TODO Auto-generated method stubreturn false;}@Overridepublic boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,float distanceY) {// TODO Auto-generated method stubreturn false;}@Overridepublic void onLongPress(MotionEvent e) {// TODO Auto-generated method stub}@Overridepublic boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {setAnimation(AnimationUtils.loadAnimation(mContext, R.anim.push_right_in)); if (e1.getX() - e2.getX() > 10 || e1.getX() - e2.getX() < -10) { showNext(); // if(R.id.silent == flipper.getCurrentView().getId()) return true; } return false;} }
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"><alpha android:fromAlpha="1.0" android:toAlpha="1.0"/></set>
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:id="@+id/ll"> <hyz.com.viewflipper.MyViewFlipper android:layout_width="wrap_content" android:layout_height="wrap_content"> <include layout="@layout/on"/> <include layout="@layout/silent"/> </hyz.com.viewflipper.MyViewFlipper></LinearLayout>on.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/on" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/btn_sound_silent" android:layout_alignParentRight="true" android:layout_marginTop="10dip" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="267dip" android:layout_marginTop="12dip" android:text="on" android:textColor="#4c4c4c" android:textSize="16px" /></RelativeLayout>silent.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/silent"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/btn_sound_on" android:layout_marginTop="10dip" android:layout_alignParentRight="true" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="silent" android:layout_marginLeft="283dip" android:layout_marginTop="12dip" android:textColor="#bfbfbf" android:textSize="16px"/></RelativeLayout>
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer