Android利用属性动画实现优酷菜单
作者:常利兵 发布时间:2022-06-15 13:16:44
标签:Android,优酷,菜单
利用属性动画实现优酷菜单,供大家参考,具体内容如下
布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="280dip"
android:layout_height="140dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/level3"
android:background="@drawable/level3" >
<ImageButton
android:id="@+id/c1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="6dip"
android:layout_marginLeft="12dip"
android:background="@drawable/channel1" />
<ImageButton
android:id="@+id/c2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/c1"
android:layout_marginBottom="12dip"
android:layout_marginLeft="28dip"
android:background="@drawable/channel2" />
<ImageButton
android:id="@+id/c3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/c2"
android:layout_marginBottom="6dip"
android:layout_marginLeft="8dip"
android:layout_toRightOf="@id/c2"
android:background="@drawable/channel3" />
<ImageButton
android:id="@+id/c4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="6dip"
android:background="@drawable/channel4" />
<ImageButton
android:id="@+id/c5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/c6"
android:layout_marginBottom="6dip"
android:layout_marginRight="8dip"
android:layout_toLeftOf="@+id/c6"
android:background="@drawable/channel5" />
<ImageButton
android:id="@+id/c6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/c7"
android:layout_marginBottom="12dip"
android:layout_marginRight="28dip"
android:layout_alignParentRight="true"
android:background="@drawable/channel6" />
<ImageButton
android:id="@+id/c7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="6dip"
android:layout_marginRight="12dip"
android:layout_alignParentRight="true"
android:background="@drawable/channel7" />
</RelativeLayout>
<RelativeLayout
android:layout_width="180dip"
android:layout_height="90dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="@+id/level2"
android:background="@drawable/level2" >
<ImageButton
android:id="@+id/search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="10dip"
android:background="@drawable/icon_search" />
<ImageButton
android:id="@+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_margin="6dip"
android:background="@drawable/icon_menu" />
<ImageButton
android:id="@+id/myyouku"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_margin="10dip"
android:background="@drawable/icon_myyouku" />
</RelativeLayout>
<RelativeLayout
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/level1" >
<ImageButton
android:id="@+id/home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/icon_home" />
</RelativeLayout>
</RelativeLayout>
核心代码
package com.example.uumusic.menu;
import android.content.Context;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.example.uumusic.R;
import com.example.uumusic.fragment.base.BasePager;
import com.example.uumusic.utils.Tools;
import butterknife.ButterKnife;
import butterknife.InjectView;
/**
* Created by Administrator on 2017.06.07.0007.
*/
public class YoukuMenu extends BasePager {
@InjectView(R.id.c1)
ImageButton c1;
@InjectView(R.id.c2)
ImageButton c2;
@InjectView(R.id.c3)
ImageButton c3;
@InjectView(R.id.c4)
ImageButton c4;
@InjectView(R.id.c5)
ImageButton c5;
@InjectView(R.id.c6)
ImageButton c6;
@InjectView(R.id.c7)
ImageButton c7;
@InjectView(R.id.level3)
RelativeLayout level3;
@InjectView(R.id.search)
ImageButton search;
@InjectView(R.id.menu)
ImageButton menu;
@InjectView(R.id.myyouku)
ImageButton myyouku;
@InjectView(R.id.level2)
RelativeLayout level2;
@InjectView(R.id.home)
ImageButton home;
private boolean isLeve12 = true;
private boolean isLeve13 = true;
public YoukuMenu(Context context) {
super(context);
}
@Override
public View initView() {
View view = View.inflate(mContext, R.layout.fragment_youku, null);
ButterKnife.inject(this,view);
return view;
}
@Override
public void initData() {
//为按钮设置点击事件
home.setOnClickListener(new MyOnClickLisetner());
menu.setOnClickListener(new MyOnClickLisetner());
}
class MyOnClickLisetner implements View.OnClickListener{
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.home:
//当点击home按钮时,开始进行动画的效果
if (isLeve12){
isLeve12 = false;
Tools.hide(level2);
if (isLeve13){
isLeve13 = false;
Tools.hide(level3,200);
}
}else {
isLeve12 = true;
Tools.show(level2);
}
break;
case R.id.menu:
if (isLeve13){
isLeve13 = false;
Tools.hide(level3);
}else {
isLeve13 = true;
Tools.show(level3);
}
break;
}
}
}
}
动画工具类
package com.example.uumusic.utils;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.RotateAnimation;
import android.widget.RelativeLayout;
/**
* Created by Administrator on 2017.06.07.0007.
*/
public class Tools {
//隐藏布局
public static void hide(ViewGroup view) {
hide(view, 0);
}
//显示布局
public static void show(ViewGroup view) {
//使用属性动画实现菜单的旋转
ObjectAnimator animator = ObjectAnimator.ofFloat(view,"rotation",180,360);
//设置动画时长
animator.setDuration(300);
animator.start();
view.setPivotX(view.getWidth()/2);
view.setPivotY(view.getHeight());
}
//延迟隐藏
public static void hide(ViewGroup view, int i) {
ObjectAnimator animator = ObjectAnimator.ofFloat(view,"rotation",0,180);
//设置动画时长
animator.setDuration(300);
//设置延迟
animator.setStartDelay(i);
animator.start();
view.setPivotX(view.getWidth()/2);
view.setPivotY(view.getHeight());
}
}
源码:Android利用属性动画实现优酷菜单
来源:https://blog.csdn.net/qq_32890771/article/details/72911030


猜你喜欢
- 一、系统启动后注入配置package com.example.config;import org.springframework.beans
- 最近一段时间 某台服务器上的一个应用总是隔一段时间就自己挂掉 用top看了看 从重新部署应用开始没有多长时间CPU占用上升得很快排查步骤1.
- 在springmvc中controller的结果集可通过json格式传到js前端接受,也可以通过Map传给前端,具体实现如下1,通过json
- 本文实例为大家分享了Android悬浮窗菜单的具体代码,供大家参考,具体内容如下MainActivity.java代码:package si
- 使用 try/catch 处理异常try-catch 块的用途是捕捉和处理工作代码所生成的异常。 有些异常可以在 catch 块中处理,解决
- 本文实例讲述了C#实现的文件上传下载工具类。分享给大家供大家参考,具体如下:这里给出的工具类是在VS2013环境下采用C#语言实现文件上传、
- 什么是粘包/拆包 一般所谓的TCP粘包是在一次接收数据不能完全地体现
- 一、需求分析最近公司项目要实现一个需求要满足以下功能: 1)显示一个 list
- 1. 什么是λ表达式λ表达式本质上是一个匿名方法。让我们来看下面这个例子: public int add(int x, int
- 介绍无论是在WPF中还是WinForm中,都有用户控件(UserControl)和自定义控件(CustomControl),这两种控件都是对
- 本文实例为大家分享了C#端口扫描器的编写代码,供大家参考,具体内容如下一、项目设计新建项目整体设计最终设计二、单线程1.代码编写button
- 简述:观察Byte值转为字符写入文件如果在java里用byte打印出来只有33 到 126的输出字符比较正常此外发现Byte值为13是空格,
- 这篇文章主要介绍了java io读取文件操作代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友
- TextView加载字体包在 Android 中,若需要使得某个TextView加载字体包,使用以下方式即可: Typeface typeF
- Android 自定义imageview实现图片缩放实例详解 觉得这个自定义的imageview很好用 性能不错 所以
- 前言Future的问题写多线程程序的时候,可以使用Future从一个异步线程中拿到结果,但是如果使用过程中会发现一些问题:如果想要对Futu
- 一、电量统计模块概述耗电信息在设置 -> 电量中能够非常直观的看到。注意,Android 所有功耗统计都是通过代码估算,没有集成电路参
- 自定义对象作为HashMap的Key这个问题在很多面试者面试时都会被提及,本人也是最近在看effective java第九条:覆盖equal
- 如果我们在浏览器地址栏乱敲的时候,所敲入的所有未定义的URL都能被程序捕捉到,然后转到一个自制的404错误处理页面。先看效果图登陆页面主页面
- (一)打包与运行SpringBoot项目快速启动(Linux版)基于Linux (CenteroS7)安装JDK,且版本不低于打包时使用的J