java 模仿优酷,自定义菜单,仿优酷菜单

2023-10-11 08:10

本文主要是介绍java 模仿优酷,自定义菜单,仿优酷菜单,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

效果图如下:点击主页后,上面2个圆环旋转消失与出现,点击中间圆环的中间那个菜单按钮,最外围的圆环旋转消失于出现

ea9744a76b48f2fb22e0576dc9a74a91.png

利用了自定义控件技术,以及图片的旋转和布局时各个控件的相对关系。

1、acitivity_main.xml的布局文件<?xml  version="1.0" encoding="utf-8"?>

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context="com.yuanlp.youkudemo.MainActivity">

android:id="@+id/level3"

android:layout_width="280dp"

android:layout_height="140dp"

android:layout_alignParentBottom="true"

android:layout_centerHorizontal="true"

android:background="@drawable/level3">

android:id="@+id/channel1"

android:layout_marginLeft="8dp"

android:layout_marginBottom="8dp"

android:layout_alignParentBottom="true"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/channel1"/>

android:id="@+id/channel2"

android:layout_above="@+id/channel1"

android:layout_marginLeft="34dp"

android:layout_marginBottom="8dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/channel2"/>

android:id="@+id/channel3"

android:layout_above="@+id/channel2"

android:layout_marginLeft="66dp"

android:layout_marginBottom="8dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/channel3"/>

android:id="@+id/channel4"

android:layout_marginTop="8dp"

android:layout_centerHorizontal="true"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/channel4"/>

android:id="@+id/channel5"

android:layout_above="@+id/channel6"

android:layout_marginRight="67dp"

android:layout_marginBottom="8dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:src="@drawable/channel5"/>

android:id="@+id/channel6"

android:layout_above="@+id/channel7"

android:layout_marginRight="27dp"

android:layout_marginBottom="8dp"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:src="@drawable/channel6"/>

android:id="@+id/channel7"

android:layout_marginRight="9dp"

android:layout_marginBottom="8dp"

android:layout_alignParentBottom="true"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:src="@drawable/channel7"/>

android:id="@+id/level2"

android:layout_width="180dp"

android:layout_height="90dp"

android:layout_alignParentBottom="true"

android:layout_centerHorizontal="true"

android:background="@drawable/level2">

android:layout_marginLeft="8dp"

android:layout_marginBottom="8dp"

android:layout_alignParentBottom="true"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/icon_search"/>

android:id="@+id/icon_menu"

android:layout_centerHorizontal="true"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="8dp"

android:src="@drawable/icon_menu"/>

android:layout_marginLeft="8dp"

android:layout_marginBottom="8dp"

android:layout_alignParentBottom="true"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:src="@drawable/icon_myyouku"/>

android:id="@+id/level1"

android:layout_centerHorizontal="true"

android:layout_alignParentBottom="true"

android:layout_width="100dp"

android:layout_height="50dp"

android:background="@drawable/level1">

android:id="@+id/icon_home"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerInParent="true"

android:src="@drawable/icon_home"/>

2、Tools.java 工具类,具体实现了消失与出现的方法,利用了图片的旋转消失package com.yuanlp.youkudemo;

import android.view.View;

import android.view.animation.RotateAnimation;

/**

* Created by 原立鹏 on 2017/7/3.

* 控制level的指定的看控件

*/

class Tools {

public static void hideView(View view){

//参数解释:第一个蚕食是从多少开始,第二个是旋转多少度,第三个以及第四个是相对于控件来说,旋转中心的位置,即控件宽度的一半以及高度

RotateAnimation ra=new RotateAnimation(0,180,view.getWidth()/2,view.getHeight());

ra.setDuration(500);  //设置动画的时间,不然的话直接就没了,没有视觉效果

ra.setFillAfter(true);  //动画停留在完成的状态

view.startAnimation(ra);  //启动动画

}

public static void showView(View view) {

//参数解释:第一个蚕食是从多少开始,第二个是旋转多少度,第三个以及第四个是相对于控件来说,旋转中心的位置,即控件宽度的一半以及高度

RotateAnimation ra=new RotateAnimation(180,360,view.getWidth()/2,view.getHeight());

ra.setDuration(500);  //设置动画的时间,不然的话直接就没了,没有视觉效果

ra.setFillAfter(true);  //动画停留在完成的状态

view.startAnimation(ra);  //启动动画

}

}

3、MainActivity.javapackage com.yuanlp.youkudemo;

import android.os.Bundle;

import android.support.v7.app.AppCompatActivity;

import android.view.View;

import android.widget.ImageView;

import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity {

private ImageView icon_home;

private ImageView icon_menu;

private RelativeLayout level1;

private RelativeLayout level2;

private RelativeLayout level3;

//定义一个状态,来控制level3是否显示

private boolean isShowLevel3=true;

//定义一个状态,来控制level2是否显示

private boolean isShowLevel2=true;

//定义一个状态,来控制level1是否显示

private boolean isShowLevel1=true;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

level1= (RelativeLayout) findViewById(R.id.level1);

level2= (RelativeLayout) findViewById(R.id.level2);

level3= (RelativeLayout) findViewById(R.id.level3);

icon_home= (ImageView) findViewById(R.id.icon_home);

icon_menu= (ImageView) findViewById(R.id.icon_menu);

MyOnClickListener myOnClickListener=new MyOnClickListener();

icon_home.setOnClickListener(myOnClickListener);

icon_menu.setOnClickListener(myOnClickListener);

}

class MyOnClickListener implements View.OnClickListener {

@Override

public void onClick(View v) {

switch (v.getId()){

case R.id.icon_home:

//如果三级菜单和二级菜单都是现实的,那么把2个都设置隐藏

if (isShowLevel2){

isShowLevel2=false;

Tools.hideView(level2);

if (isShowLevel3){

isShowLevel3=false;

Tools.hideView(level3);

}

}else{

isShowLevel2=true;

Tools.showView(level2);

}

//如果三级菜单和二级菜单都是隐藏的,就显示二级菜单

break;

case R.id.icon_menu:

if (isShowLevel3){

//隐藏

isShowLevel3=false;

Tools.hideView(level3);

}else{

isShowLevel3=true;

Tools.showView(level3);

}

break;

}

}

}

}

这篇关于java 模仿优酷,自定义菜单,仿优酷菜单的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/186703

相关文章

Spring Security自定义身份认证的实现方法

《SpringSecurity自定义身份认证的实现方法》:本文主要介绍SpringSecurity自定义身份认证的实现方法,下面对SpringSecurity的这三种自定义身份认证进行详细讲解,... 目录1.内存身份认证(1)创建配置类(2)验证内存身份认证2.JDBC身份认证(1)数据准备 (2)配置依

SpringBoot整合OpenFeign的完整指南

《SpringBoot整合OpenFeign的完整指南》OpenFeign是由Netflix开发的一个声明式Web服务客户端,它使得编写HTTP客户端变得更加简单,本文为大家介绍了SpringBoot... 目录什么是OpenFeign环境准备创建 Spring Boot 项目添加依赖启用 OpenFeig

Java Spring 中 @PostConstruct 注解使用原理及常见场景

《JavaSpring中@PostConstruct注解使用原理及常见场景》在JavaSpring中,@PostConstruct注解是一个非常实用的功能,它允许开发者在Spring容器完全初... 目录一、@PostConstruct 注解概述二、@PostConstruct 注解的基本使用2.1 基本代

springboot使用Scheduling实现动态增删启停定时任务教程

《springboot使用Scheduling实现动态增删启停定时任务教程》:本文主要介绍springboot使用Scheduling实现动态增删启停定时任务教程,具有很好的参考价值,希望对大家有... 目录1、配置定时任务需要的线程池2、创建ScheduledFuture的包装类3、注册定时任务,增加、删

SpringBoot整合mybatisPlus实现批量插入并获取ID详解

《SpringBoot整合mybatisPlus实现批量插入并获取ID详解》这篇文章主要为大家详细介绍了SpringBoot如何整合mybatisPlus实现批量插入并获取ID,文中的示例代码讲解详细... 目录【1】saveBATch(一万条数据总耗时:2478ms)【2】集合方式foreach(一万条数

IntelliJ IDEA 中配置 Spring MVC 环境的详细步骤及问题解决

《IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决》:本文主要介绍IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决,本文分步骤结合实例给大... 目录步骤 1:创建 Maven Web 项目步骤 2:添加 Spring MVC 依赖1、保存后执行2、将新的依赖

SpringBoot中配置文件的加载顺序解读

《SpringBoot中配置文件的加载顺序解读》:本文主要介绍SpringBoot中配置文件的加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot配置文件的加载顺序1、命令⾏参数2、Java系统属性3、操作系统环境变量5、项目【外部】的ap

SpringBoot UserAgentUtils获取用户浏览器的用法

《SpringBootUserAgentUtils获取用户浏览器的用法》UserAgentUtils是于处理用户代理(User-Agent)字符串的工具类,一般用于解析和处理浏览器、操作系统以及设备... 目录介绍效果图依赖封装客户端工具封装IP工具实体类获取设备信息入库介绍UserAgentUtils

Spring 中的循环引用问题解决方法

《Spring中的循环引用问题解决方法》:本文主要介绍Spring中的循环引用问题解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录什么是循环引用?循环依赖三级缓存解决循环依赖二级缓存三级缓存本章来聊聊Spring 中的循环引用问题该如何解决。这里聊

Java学习手册之Filter和Listener使用方法

《Java学习手册之Filter和Listener使用方法》:本文主要介绍Java学习手册之Filter和Listener使用方法的相关资料,Filter是一种拦截器,可以在请求到达Servl... 目录一、Filter(过滤器)1. Filter 的工作原理2. Filter 的配置与使用二、Listen