滑動 建國科技大學 資管系 饒瑞佶.

Slides:



Advertisements
Similar presentations
Getting Started with Android APIs Ivan Wong. Motivation - “Datasheet” - Recently exposed to what’s available in Android - So let’s see what API’s are.
Advertisements

Android Tutorial Team 3 Jerry Yu Mayank Mandava Mu Du Will Wangles.
Package org.androidtown.database.query; import android.app.Activity; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase;
1 Mobile Computing Advanced Touching Copyright 2014 by Janson Industries Assg Part1Assg Part1 AssgPart2AssgPart2.
Animation.
로봇 전화번호부 4/4 UNIT 12 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 뷰 홀더 패턴을 사용할 수 있다. 토스트를 사용할 수 있다. 클릭 이벤트를 처리할 수 있다. 2.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
Create Navigation Drawer Team 2 Zhong Wang Jiaming Dong Philip Wu Lingduo Kong.
Android - Broadcast Receivers
로봇을 조종하자 3/4 UNIT 17 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 스마트 폰의 센서를 사용할 수 있다. 2.
Networking: Part 1 (Web Content). Networking with Android Android provides A full-featured web browser based on Chromium, the open source browser engine.
Import import android.graphics.Bitmap; import android.widget.ImageView;
로봇 모니터링 1/2 UNIT 20 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Message Queue Handler 2.
Mobile Programming Lecture 12 HierarchyViewer, Linkify, Gestures, and Version Control.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
Android View Stuff. TextViews Display text Display images???
Android and s Ken Nguyen Clayton state University 2012.
로봇을 조종하자 1/5 UNIT 14 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 터치 이벤트를 처리할 수 있다. 2.
Custom Widget 2 UNIT 27 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Custom Widget –Canvas 를 이용하여 Custom Widget 을 만든다. 2.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Google map v2.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Lab7 – Appendix.
Introduction to android
TUTORIAL ON MULTITOUCH AND SWIPE GESTURES
Android Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
CS240: Advanced Programming Concepts
GUI Programming Fundamentals
Further android gui programming
滑動版面 建國科技大學 資管系 饒瑞佶 2013/7 V1.
CS499 – Mobile Application Development
S.RENUKADEVI/AP/SCD/ANDROID - Notifications
Android Widgets 1 7 August 2018
Android Introduction Hello Views Part 1.
Android – Read/Write to External Storage
Picasso Revisted.
Android Introduction Hello Views Part 2.
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android Programming Lecture 6
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android Sensor Programming
CMPE419 Mobile Application Development
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
Activities and Intents
滑動 建國科技大學 資管系 饒瑞佶 2013/4 V1 2015/5 V2.
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Mobile Programming Gestures in Android.
Adding Components to Activity
BLP 4216 MOBİL UYGULAMA GELİŞTİRME-2
CMPE419 Mobile Application Development
CS 240 – Advanced Programming Concepts
Lasalle-App Tecnología Móvil.
CIS 470 Mobile App Development
User Interface Development
Mobile Programming Broadcast Receivers.
Android Sensor Programming
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
User Interface Development
CIS 694/EEC 693 Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

滑動 建國科技大學 資管系 饒瑞佶

利用既有XML畫面 首先加入一個ViewFlipper到xml畫面中 <ViewFlipper android:id="@+id/viewFlipper1" android:layout_width="match_parent" android:layout_height="match_parent" >

利用既有XML畫面 其次,將要滑動的版面依序放在ViewFlipper中 <ViewFlipper android:id="@+id/viewFlipper1" android:layout_width="match_parent" android:layout_height="match_parent" > <include android:id="@+id/layout01" layout="@layout/bmi" /> android:id="@+id/layout02" layout="@layout/bmirelative" /> </ViewFlipper> 這個順序就是滑動順序

滑動主程式 首先增加OnTouchListener監聽事件 加入物件宣告 加入物件在onCreate public class Main extends Activity implements OnTouchListener { private ViewFlipper viewFlipper; private float touchDownX;//手指按下去的x座標 private float touchUpX; //手指放開的x座標 //取得ViewFlipper物件 viewFlipper = (ViewFlipper) findViewById(R.id.viewFlipper1); viewFlipper.setOnTouchListener(this);

滑動主程式 需要加入必要的ontouch事件 @Override public boolean onTouch(View arg0, MotionEvent event) {

Ontouch事件 if (event.getAction() == MotionEvent.ACTION_DOWN) { // 左右滑動時手指按的x座標 touchDownX = event.getX(); return true; } else if (event.getAction() == MotionEvent.ACTION_UP) { // 左右滑動時手指鬆開的x座標 touchUpX = event.getX(); // 從左往右滑動 if (touchUpX - touchDownX > 100) { // 顯示上一個畫面的動畫 viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_in)); viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_out)); // 顯示上一個畫面 viewFlipper.showPrevious(); // 從右往左滑動 } else if (touchDownX - touchUpX > 100) { //顯示上一個畫面的動畫 R.anim.push_left_in)); R.anim.push_left_out)); // 顯示下一個畫面 viewFlipper.showNext(); }

push_left_in.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="500" /> <alpha android:fromAlpha="0.1" android:toAlpha="1.0" </set>

push_left_out.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="500" /> <alpha android:fromAlpha="1.0" android:toAlpha="0.1" </set>

push_right_in.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="500" /> <alpha android:fromAlpha="0.1" android:toAlpha="1.0" </set>

push_right_out.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="100%p" android:duration="500" /> <alpha android:fromAlpha="1.0" android:toAlpha="0.1" </set>

加入畫面物件事件 依照原本處理事件方式處理就可以 但ViewFlipper碰到ScrollView會失效

ViewPager

activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </RelativeLayout>

修改Home.java private ViewPager mViewPager; List<View> viewList; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LayoutInflater mInflater = getLayoutInflater().from(this); View v1 = mInflater.inflate(R.layout.home, null); View v2 = mInflater.inflate(R.layout.bmi, null); View v3 = mInflater.inflate(R.layout.main4, null); //加入需要的頁面 viewList = new ArrayList<View>(); viewList.add(v1); viewList.add(v2); viewList.add(v3);

// 將所有版面加入 mViewPager = (ViewPager) findViewById(R.id.viewpager); mViewPager.setAdapter(new MyViewPagerAdapter(viewList)); mViewPager.setCurrentItem(0); // 設置預設要顯示的頁面 // 找到畫面上需要的View View view = viewList.get(0); Button intentbutton=(Button)view.findViewById(R.id.intentbutton); // 定義(set)物件intentbutton的事件click intentbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 跳到Main2.java // 跳Activity用的是Intent類別 Intent it=new Intent(); it.setClass(Home.this,Main2.class); startActivity(it); } });

MyViewPagerAdapter.java class MyViewPagerAdapter extends PagerAdapter { private List<View> mListViews; public MyViewPagerAdapter(List<View> mListViews) { this.mListViews = mListViews; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); public Object instantiateItem(ViewGroup container, int position) { View view = mListViews.get(position); container.addView(view); return view; public int getCount() { return mListViews.size(); public boolean isViewFromObject(View arg0, Object arg1) { return arg0==arg1;

同時保有ScrollView與滑動