UI复习练习_优酷布局

还记得前一周,细致看了一下我自己的代码,特意看了下代码规范,一个好的代码习惯就应该慢慢增加自己寻常练习中。

看看UI吧

我是想特意今天复习下曾经忽视的UI知识,事实上作为一个开发者要习惯相对布局,第一呢。能够拖拉成布局,第二呢 从安卓性能来说相对布局。远远好于线性布局。

这个布局呢 是通过三个相对布局 和图片形成了。

一个相对布局。背景是一张图片,和一个Imageview组成的  我将其它布局隐藏了 给大家看看

    <RelativeLayoutandroid:id="@+id/level1"android:layout_width="100dp"android:layout_height="50dp"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:background="@drawable/level1" ><ImageViewandroid:id="@+id/icon_home"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:background="@drawable/icon_home" /></RelativeLayout>

android:layout_alignParentBottom="true"  是否显示在容器底部

android:layout_centerHorizontal:用于相对布局(RelativeLayout)的子控件居中。

这两个属性在后面也会经经常使用到.

相信大家也能知道第二层是怎么弄出来的

一个相对布局  三个Imageview  只是图片做过处理 是斜着的的。

<RelativeLayoutandroid:id="@+id/level2"android:layout_width="180dp"android:layout_height="90dp"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:background="@drawable/level2" ><ImageViewandroid:id="@+id/icon_search"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_margin="10dp"android:background="@drawable/icon_search" /><ImageViewandroid:id="@+id/icon_menu"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_marginTop="5dp"android:background="@drawable/icon_menu" /><ImageViewandroid:id="@+id/icon_myyouku"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_alignParentRight="true"android:layout_margin="10dp"android:background="@drawable/icon_myyouku" /></RelativeLayout>

android:layout_margin="10dp" 则是站在自己的角度描写叙述问题,规定自己和其它(上下左右)的view之间的距离

第三层  主要难点在于怎么对其。 解决方式就是 左对齐上一个组件,然后条margin值 就能够攻克了。

所有代码~~~~

<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" ><RelativeLayoutandroid:id="@+id/level1"android:layout_width="100dp"android:layout_height="50dp"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:background="@drawable/level1" ><ImageViewandroid:id="@+id/icon_home"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:background="@drawable/icon_home" /></RelativeLayout><RelativeLayoutandroid:id="@+id/level2"android:layout_width="180dp"android:layout_height="90dp"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:background="@drawable/level2" ><ImageViewandroid:id="@+id/icon_search"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_margin="10dp"android:background="@drawable/icon_search" /><ImageViewandroid:id="@+id/icon_menu"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_marginTop="5dp"android:background="@drawable/icon_menu" /><ImageViewandroid:id="@+id/icon_myyouku"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_alignParentRight="true"android:layout_margin="10dp"android:background="@drawable/icon_myyouku" /></RelativeLayout><RelativeLayoutandroid:id="@+id/level3"android:layout_width="280dp"android:layout_height="140dp"android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:background="@drawable/level3" ><ImageViewandroid:id="@+id/channel1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_marginBottom="10dp"android:layout_marginLeft="10dp"android:background="@drawable/channel1" /><ImageViewandroid:id="@+id/channel2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@id/channel1"android:layout_alignLeft="@id/channel1"android:layout_marginBottom="6dp"android:layout_marginLeft="20dp"android:background="@drawable/channel2" /><ImageViewandroid:id="@+id/channel3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@id/channel2"android:layout_alignLeft="@id/channel2"android:layout_marginBottom="6dp"android:layout_marginLeft="30dp"android:background="@drawable/channel3" /><ImageViewandroid:id="@+id/channel4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerHorizontal="true"android:layout_marginTop="5dp"android:background="@drawable/channel4" /><ImageView android:id="@+id/channel7"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="@drawable/channel7"android:layout_alignParentBottom="true"android:layout_alignParentRight="true"android:layout_marginBottom="10dp"android:layout_marginRight="10dp"/><ImageViewandroid:id="@+id/channel6"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@id/channel7"android:layout_alignRight="@id/channel7"android:layout_marginBottom="6dp"android:layout_marginRight="20dp"android:background="@drawable/channel6" /><ImageViewandroid:id="@+id/channel5"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_above="@id/channel6"android:layout_alignRight="@id/channel6"android:layout_marginBottom="6dp"android:layout_marginRight="30dp"android:background="@drawable/channel5" /></RelativeLayout></RelativeLayout>

好啦。 UI实现了以后再看java 代码吧

思路 通过 点击Imageview 显示下一级菜单 SO, 出来和隐藏式通过动画效果实现的。

------------------------------第一步实例化控件-----------------------------------------

    private ImageView icon_menu;private ImageView icon_home;private RelativeLayout level1;private RelativeLayout level2;private RelativeLayout level3;
 /*** 初始化控件并增加点击事件*/private void initView() {icon_home = (ImageView) findViewById(R.id.icon_home);icon_menu = (ImageView) findViewById(R.id.icon_menu);level1 = (RelativeLayout) findViewById(R.id.level1);level2 = (RelativeLayout) findViewById(R.id.level2);level3 = (RelativeLayout) findViewById(R.id.level3);icon_home.setOnClickListener(this);icon_menu.setOnClickListener(this);}

最重要的就是点击事件处理了。

第二步,通过标识符 。推断是否显示下一级列表

 /* 点击事件处理* @see android.view.View.OnClickListener#onClick(android.view.View)*/@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.icon_menu: //menu图标的点击事件处理// 假设第3级菜单是显示状态,那么将其隐藏if (isLevel3Show) {//隐藏 第3级菜单AnimUtils.startAnimOut(level3);}else{// 假设第3级菜单是隐藏状态,那么将其显示AnimUtils.startAnimIn(level3);}//取反 把状态调整hao isLevel3Show = !isLevel3Show;break;case R.id.icon_home: //home图标的点击事件处理// 假设第2级菜单是显示状态,那么就隐藏。2。3级菜单if (isLevel2Show) {AnimUtils.startAnimOut(level2);isLevel2Show=false;if (isLevel3Show) {AnimUtils.startAnimOut(level3,300);isLevel3Show=false;}}else{// 假设第2级菜单是隐藏状态,那么就显示2级菜单AnimUtils.startAnimIn(level2);isLevel2Show=true;}break;default:break;}}

----------------------------第三步,制作动画工具类-------------------------

动画旋转有一个类  RotateAnimation 我就用它 进行将相对布局的旋转实现 是否显示

package com.xiaoxin.youkuDemo;import android.view.animation.RotateAnimation;
import android.widget.RelativeLayout;/**float fromDegrees:旋转的開始角度。float toDegrees:旋转的结束角度。

int pivotXType:X轴的伸缩模式,能够取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。 float pivotXValue:X坐标的伸缩值。 int pivotYType:Y轴的伸缩模式,能够取值为ABSOLUTE、RELATIVE_TO_SELF、RELATIVE_TO_PARENT。 float pivotYValue:Y坐标的伸缩值。 * @author Administrator */ public class AnimUtils { /** * 让指定的view 运行 旋转离开的动画 * @param view */ public static void startAnimOut(RelativeLayout view) { startAnimOut(view, 0); } public static void startAnimOut(RelativeLayout view,long offest){ //第一个參数是 開始旋转的角度, //第二个參数是结束的角度 //第三。四个參数是圆心的坐标 RotateAnimation animation=new RotateAnimation(0, 180,view.getWidth()/2,view.getHeight()); //1.设置运行的事件 animation.setDuration(500); //2.动画运行完保存状态 animation.setFillAfter(true); //3.设置延时运行的事件 animation.setStartOffset(offest); //4.运行 view.startAnimation(animation); } /** * 让指定的view 运行 旋转进入的动画 * @param view */ public static void startAnimIn(RelativeLayout view) { startAnimIn(view, 0); } /** * 让指定的view 延时运行 旋转进入的动画 * @param level2 * @param i 延时的时间 */ public static void startAnimIn(RelativeLayout view, int i) { /* * 默认圆为 为view的左上角, * 水平向右 为 0度 * 顺时针旋转度数添加 */ RotateAnimation animation =new RotateAnimation(180, 360, view.getWidth()/2, view.getHeight()); animation.setDuration(500); // 设置运行的时间 animation.setFillAfter(true); //动画运行完以后。保持最后的状态 animation.setStartOffset(i); //设置延时运行的时间 view.startAnimation(animation); } }

------------------最后一步添加人性化操作,将菜单键进行监控 激发显示菜单和隐藏菜单的功能

//   -------------------------利用菜单键控制布局---------------------@Override/*** 响应按键的动作*/public boolean onKeyDown(int keyCode, KeyEvent event) {if(keyCode == KeyEvent.KEYCODE_MENU){ // 监听 menu 按键changeLevel1State();}return super.onKeyDown(keyCode, event);}
  private void changeLevel1State() {//假设第1级菜单是显示状态,那么就隐藏 1,2。3级菜单 if(isLevel1show){AnimUtils.startAnimOut(level1);isLevel1show = false;if(isLevel2Show){ // 推断2级菜单是否显示AnimUtils.startAnimOut(level2,100);isLevel2Show = false;if(isLevel3Show){ // 推断3级菜单是否显示AnimUtils.startAnimOut(level3,200);isLevel3Show = false;}}}else{//假设第1级菜单是隐藏状态,那么就显示 1,2级菜单 AnimUtils.startAnimIn(level1);isLevel1show = true;AnimUtils.startAnimIn(level2,200);isLevel2Show = true;}}

End ------------

点击下载源代码

posted on 2017-04-20 12:24 mthoutai 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/mthoutai/p/6738111.html

UI复习练习_优酷布局相关推荐

  1. 优酷视频怎么转二维码_优酷视频转二维码

    有的人想将自己制作的视频分享出去,那么该如何将视频转换成二维码来分享呢?其实方法很简单,直接在视频界面中就能生成,这里和大家讲讲. 01. 登录自己的优酷帐号,然后点击右上角的上传按钮. 优酷视频怎么 ...

  2. mac地址修改_优酷路由宝救砖时MAC和无线参数及SN恢复方法

    科普:成砖和救砖 路由器刷机时如果中途断电或者其他特殊情况,可能导致路由器无法启动,也就是俗称成砖.这时候就需要用编程器直接对路由器闪存进行读写,重新刷入固件称为救砖. 一般的救砖办法是,用编程器写入 ...

  3. 优酷路由宝刷梅林_优酷路由宝刷breed(不死)教程

    一.准备 1.下载PuTTY软件 (全篇仅用到此软件) 下载降级固件,(网上说的升级固件其实就是降级固件)需要带telnent功能的,不要随意选择,这一步很关键,不然就会出错,我选择1119telne ...

  4. 24小时轮播怎么实现的_优酷24小时轮播台如何使用

    优酷24小时轮播台如何使用相信有很多小伙伴对此存在疑惑,接下来就跟着IEfans小编一起了解一下使用优酷24小时轮播台方法分享! 工具/原料 手机(设备名称:华为荣耀V8.系统版本:EMUI 8.0. ...

  5. 优酷路由宝刷梅林_优酷路由宝 YK-L1c 和 YK-L1 刷入 Breed 不死和 hiboy Padavan 固件...

    优酷路由宝 YK-L1c 和 YK-L1 刷入 Breed 不死和 hiboy Padavan 固件 2020-04-06 15:38:14 4点赞 31收藏 15评论 你是AMD Yes党?还是in ...

  6. 优酷路由宝安装php,优酷路由宝怎么设置_优酷路由器怎么安装?-192路由网

    本文主要介绍了优酷路由宝(器)的安装.上网设置.无线WiFi名称和密码设置.管理密码设置等内容.优酷路由宝(器)有普通版.旗舰版.黄金版.京东白条版等等好几个版本,本文将用普通版的优酷路由宝为例,来介 ...

  7. 优酷html版,优酷视频网页版_优酷视频网站版_优酷视频网页

    最迅速的视频搜索:在自主开发的定向搜索技术和海量数据精准处理方式支持下,达到方便的专辑分类交叉搜索. 多元化内容:从网剧.网络小说.网络综艺.资讯栏目等多样化内容组合贯穿,创新的栏目式,优酷出品再度掀 ...

  8. 怎么关闭苹果手机自动扣费_优酷自动续费怎么关闭

    优酷自动续费怎么关闭?历经几个月我终于关掉了,真的是普天同庆不容易.还没关掉的,就按照我圈起来的去操作,我收到短信提示关闭成功,下个月就不会自动扣钱啦!对了我是苹果手机

  9. 优酷进度条不能拖动_优酷画面一直加载中,有声音没画面,拖动进度条无效怎么办...

    优酷画面一直加载中,有声音没画面,拖动进度条无效: 1.建议用户检查网络稳定性,如果是超清视频,尝试切换成高清或标清模式进行视频观看. 2.暂停其它的下载活动, 如: BT下载.其它P2P软件的数据交 ...

最新文章

  1. keras 的 example 文件 babi_memnn.py 解析
  2. 干货 | 非常全面的谱聚类算法原理总结
  3. 【黑客免杀攻防】读书笔记6 - PE文件知识在免杀中的应用
  4. 猜数字游戏的提示(UVa340)
  5. java属于面相_[Java教程]面相对象
  6. 科学数字_七年级数学上册:科学记数法、有效数字记住这点中考分可定拿得到...
  7. 常用模块(json/pickle/shelve/XML)
  8. 洛谷P4482 [BJWC2018]Border 的四种求法 字符串,SAM,线段树合并,线段树,树链剖分,DSU on Tree...
  9. 堆排序(java完整代码)
  10. SNMP(简单网络管理协议)详解
  11. matlab风应力工具包,MSATSI:结合可靠经典方法的新简化用户处理及可视化工具的应力反演MATLAB软件包.pdf...
  12. Legion 一款网络渗透工具
  13. 基于R语言的模型组合
  14. Fourier分析入门——第1章——数学预备知识
  15. 计算机博弈问题一直是什么领域,计算机博弈是什么
  16. html中table设置滚动条
  17. 3.5计算机网络(无线局域网 PPP协议&HDLC协议 广域网 链路层设备)
  18. python爬网页、爬到前几个就不动了_python scrapy 爬取起点小说,爬虫停止在第四页不动了...
  19. ncs java 成都 面试_成都java工程师面试一般都是哪些问题,基础难不难!
  20. 超全,Python 量化金融库汇总!

热门文章

  1. 【ARM】ARM其它指令
  2. 【Linux】一步一步学Linux——sort命令(53)
  3. 【Linux系统编程】线程与进程的比较
  4. python中range 函数_Python中的range函数
  5. vue.js 默认选中select_vue.js 解决v-model让select默认选中不生效的问题
  6. 每天一道LeetCode-----在有序的二维数组中查找某个元素
  7. C++学习笔记-----在重载的赋值运算函数中调用拷贝构造函数
  8. Android NDK调试定位错误
  9. 第九章 PX4-pixhawk-姿态估计解析
  10. Fast R-CNN 个人理解