天道酬勤。也许你付出了不一定得到回报,但不付出一定得不到回报。

本讲内容:介面3D旋转

示例一效果图:

               

下面是res/layout/activity_main.xml 布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/layout_main"android:layout_width="fill_parent"android:layout_height="wrap_content"            android:orientation="vertical"><TextViewandroid:id="@+id/title"android:layout_width="wrap_content"android:layout_height="wrap_content" android:layout_gravity="center"android:gravity="center"android:textColor="#ff0000"android:text="@string/txt_main"/>          <LinearLayout android:layout_marginTop="50dip"android:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center"android:layout_gravity="center" >         <Buttonandroid:id="@+id/main_last"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="上一頁"/><Button android:id="@+id/main_next"android:layout_marginLeft="50dip"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="下一頁"/></LinearLayout></LinearLayout>

下面是res/layout/next.xml 布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:id="@+id/layout_next"android:layout_width="fill_parent"android:layout_height="wrap_content"            android:orientation="vertical"><TextViewandroid:id="@+id/title"android:layout_width="wrap_content"android:layout_height="wrap_content" android:layout_gravity="center"android:gravity="center"android:textColor="#ff0000"android:text="@string/txt_next"/>          <LinearLayout android:layout_marginTop="5dip"android:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center"android:layout_gravity="center" >          <Buttonandroid:id="@+id/next_last"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="上一頁"/><Button android:id="@+id/next_next"android:layout_marginLeft="50dip"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="下一頁"/></LinearLayout></LinearLayout>

下面是res/values/string.xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<resources><string name="app_name">Rotate3D</string><string name="hello_world">Hello world!</string><string name="action_settings">Settings</string><string name="txt_main">第一页\n\n珍爱生命</string><string name="txt_next">第二页\n远离IT</string></resources>

下面是Rotate3D.java文件:

public class Rotate3D extends Animation {private float fromDegree;   // 旋转起始角度private float toDegree;        // 旋转终止角度private float mCenterX;        // 旋转中心xprivate float mCenterY;     // 旋转中心yprivate Camera mCamera;public Rotate3D(float fromDegree, float toDegree, float centerX, float centerY) {this.fromDegree = fromDegree;this.toDegree = toDegree;this.mCenterX = centerX;this.mCenterY = centerY;}@Overridepublic void initialize(int width, int height, int parentWidth, int parentHeight) {super.initialize(width, height, parentWidth, parentHeight);mCamera = new Camera();}@Overrideprotected void applyTransformation(float interpolatedTime, Transformation t) {final float FromDegree = fromDegree;float degrees = FromDegree + (toDegree - fromDegree) * interpolatedTime;  // 旋转角度(angle)final float centerX = mCenterX;final float centerY = mCenterY;final Matrix matrix = t.getMatrix();if (degrees <= -76.0f) {degrees = -90.0f;mCamera.save();mCamera.rotateY(degrees);     // 旋转mCamera.getMatrix(matrix);mCamera.restore();} else if (degrees >= 76.0f) {degrees = 90.0f;mCamera.save();mCamera.rotateY(degrees);mCamera.getMatrix(matrix);mCamera.restore();} else {mCamera.save();mCamera.translate(0, 0, centerX);        // 位移xmCamera.rotateY(degrees);mCamera.translate(0, 0, -centerX);mCamera.getMatrix(matrix);mCamera.restore();}matrix.preTranslate(-centerX, -centerY);matrix.postTranslate(centerX, centerY);}
}

下面是MainActivity.java主界面文件:

public class MainActivity extends Activity {private ViewGroup layoutmain;private ViewGroup layoutnext;private Button btn_MainLast;private Button btn_MainNext;private Button btn_NextLast;private Button btn_NextNext;private Rotate3D lQuest1Animation;private Rotate3D lQuest2Animation;private Rotate3D rQuest1Animation;private Rotate3D rQuest2Animation;private int mCenterX = 160;       // 320x480 的宽一半private int mCenterY = 240;     // 320x480 的高一半@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initAnimation();initMain();}private void initMain(){layoutmain = (LinearLayout)findViewById(R.id.layout_main);btn_MainLast = (Button)findViewById(R.id.main_last);btn_MainNext = (Button)findViewById(R.id.main_next);btn_MainLast.setOnClickListener(listener);btn_MainNext.setOnClickListener(listener);}private void initNext(){setContentView(R.layout.next);layoutnext = (LinearLayout)findViewById(R.id.layout_next);btn_NextLast = (Button)findViewById(R.id.next_last);btn_NextNext = (Button)findViewById(R.id.next_next);btn_NextLast.setOnClickListener(listener);btn_NextNext.setOnClickListener(listener);}private View.OnClickListener listener = new View.OnClickListener() {@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.main_last:  // 上一页layoutmain.startAnimation(lQuest1Animation);  // 当前页向左旋转(0,-90)initNext();layoutnext.startAnimation(lQuest2Animation);   // 下一页向左旋转(90, 0)break;case R.id.main_next:   // 下一页layoutmain.startAnimation(rQuest1Animation);  // 当前页向右旋转(0,90)initNext();layoutnext.startAnimation(rQuest2Animation);    // 下一页向右旋转(-90, 0)break;case R.id.next_last:layoutnext.startAnimation(lQuest1Animation);initMain();layoutmain.startAnimation(lQuest2Animation);break;case R.id.next_next:layoutnext.startAnimation(rQuest1Animation);initMain();layoutmain.startAnimation(rQuest2Animation);break;}}};public void initAnimation() {// 获取旋转中心DisplayMetrics dm = new DisplayMetrics();dm = getResources().getDisplayMetrics();mCenterX = dm.widthPixels / 2;mCenterY = dm.heightPixels / 2;// 定义旋转方向int duration = 1000;lQuest1Animation = new Rotate3D(0, -90, mCenterX, mCenterY); // 下一页的旋转方向(从0度转到-90,参考系为水平方向为0度)lQuest1Animation.setFillAfter(true);lQuest1Animation.setDuration(duration);lQuest2Animation = new Rotate3D(90, 0, mCenterX, mCenterY);       // 下一页的旋转方向(从90度转到0,参考系为水平方向为0度)(起始第一题)lQuest2Animation.setFillAfter(true);lQuest2Animation.setDuration(duration);rQuest1Animation = new Rotate3D(0, 90, mCenterX, mCenterY);       // 上一页的旋转方向(从0度转到90,参考系为水平方向为0度)rQuest1Animation.setFillAfter(true);rQuest1Animation.setDuration(duration);rQuest2Animation = new Rotate3D(-90, 0, mCenterX, mCenterY);   // 上一页的旋转方向(从-90度转到0,参考系为水平方向为0度)rQuest2Animation.setFillAfter(true);rQuest2Animation.setDuration(duration);}}

Take your time and enjoy it

进阶六之Android UI介面之(介面3D旋转)相关推荐

  1. android 点击图片旋转90度,Android UI之ImageView实现图片旋转和缩放

    这一篇,给大家介绍一下ImageView控件的使用,ImageView主要是用来显示图片,可以对图片进行放大.缩小.旋转的功能. android:sacleType属性指定ImageVIew控件显示图 ...

  2. 得到谷歌认证的《Android UI框架进阶解密》开源了,亮瞎我的钛合金

    根据调查显示,,iOS与Android的市场份额差距正越来越大.Android设备正在成为手机应用市场的主力军.如何从设计层面创造一个优美的App界面来吸引用户已然成为广大App开发者们必做的功课之一 ...

  3. Android UI开发第二十五篇——分享一篇自定义的 Action Bar

    Action Bar是android3.0以后才引入的,主要是替代3.0以前的menu和tittle bar.在3.0之前是不能使用Action Bar功能的.这里引入了自定义的Action Bar, ...

  4. 我的Android进阶之旅------Android利用温度传感器实现带动画效果的电子温度计

    要想实现带动画效果的电子温度计,需要以下几个知识点: 1.温度传感器相关知识. 2.ScaleAnimation动画相关知识,来进行水印刻度的缩放效果. 3.android:layout_weight ...

  5. Android UI设计之十一自定义ViewGroup,打造通用的关闭键盘小控件ImeObser

    2019独角兽企业重金招聘Python工程师标准>>> 转载请注明出处:http://blog.csdn.net/llew2011/article/details/51598682 ...

  6. Android UI 测试指南之 Espresso

    关于 Espresso Espresso 是一个简单好用的 Android UI 测试框架 Espresso 主要由以下三个基础部分组成: ViewMatchers - 在当前View层级去匹配指定的 ...

  7. Android UI设计经验分享,掌握设计技巧,让你的应用独树一帜

    Android UI渲染是指Android应用程序中的用户界面如何被绘制.Android UI渲染很重要,因为渲染过程直接影响应用程序的性能和用户体验. 当用户在Android应用程序中进行交互时,应 ...

  8. 作为 Android 开发者,如何深入学习 Android UI?

    前言 Android 新技术层出不穷,要想不落后不被淘汰我们只能不停的学! 作为好的安卓开发,首先明确Android是前端,重点是UI,做出稳定的应用是关键. Compose 是 Android UI ...

  9. Android UI + Function

    第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.Pro ...

最新文章

  1. 即学即用的数据分析技巧
  2. ios 折线图_《解神者》ios和安卓互通吗 ios和安卓互通分析
  3. 一天star量破千,300行代码,特斯拉AI总监Karpathy写了个GPT的Pytorch训练库
  4. php完美实现下载远程图片保存到本地(保存微信头像)
  5. UVA 10129 Play on Words(欧拉道路)
  6. 2013年中国高校网购实力排行榜
  7. 【android-tips】如何在android应用中插入百度广告(附源码)
  8. activity 防止多次打开_杭州下沙罐式无负压供水设备防止水质污染变频电泵
  9. Linux C 数据结构——队列
  10. python魔术方法abstract_python学习之面向对象高级特性和魔术方法
  11. hdu 2609 How many(最小表示法)
  12. 4.Java JSON使用
  13. thinkphp页面请求时间超过40S报404错误解决办法
  14. 优酷路由宝刷梅林_【荒野无灯Padavan固件】优酷路由宝L1内存卡扩展SWAP缓存+v2瑞设置详解...
  15. python14张图下载_Python网络爬虫入门(三)—— 做个简陋的pixabay 图片下载器 (附源码)...
  16. react从入门到入魔
  17. ubuntu中firebox无法联网
  18. 【第二周】Java实现英语文章词频统计
  19. Redis详细教程-学习笔记
  20. 【观察】做好数据到介质的连接者,英特尔存储的创新与超越

热门文章

  1. 推荐五款Android 应用的自动化测试工具
  2. 开发者年度盛宴,OpenI/O 2020启智开发者大会即将开幕!
  3. flink 入门(一)
  4. 能链科技子公司上海能链获颁高新技术企业资质
  5. 如何发布一个本地网站
  6. 建仓价和持仓价的应用:如何开仓如何持仓
  7. 李国庆:建议被降级降薪员工主动辞职,网友炸了!
  8. JavaScript中绑定事件监听函数的通用方法[ addEvent() ]
  9. AjaxUpLoad.js文件上传插件的使用
  10. Hive 实战(2)--hive分区分桶实战