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

相关文章

JVM 的类初始化机制

前言 当你在 Java 程序中new对象时,有没有考虑过 JVM 是如何把静态的字节码(byte code)转化为运行时对象的呢,这个问题看似简单,但清楚的同学相信也不会太多,这篇文章首先介绍 JVM 类初始化的机制,然后给出几个易出错的实例来分析,帮助大家更好理解这个知识点。 JVM 将字节码转化为运行时对象分为三个阶段,分别是:loading 、Linking、initialization

Spring Security 基于表达式的权限控制

前言 spring security 3.0已经可以使用spring el表达式来控制授权,允许在表达式中使用复杂的布尔逻辑来控制访问的权限。 常见的表达式 Spring Security可用表达式对象的基类是SecurityExpressionRoot。 表达式描述hasRole([role])用户拥有制定的角色时返回true (Spring security默认会带有ROLE_前缀),去

浅析Spring Security认证过程

类图 为了方便理解Spring Security认证流程,特意画了如下的类图,包含相关的核心认证类 概述 核心验证器 AuthenticationManager 该对象提供了认证方法的入口,接收一个Authentiaton对象作为参数; public interface AuthenticationManager {Authentication authenticate(Authenti

Spring Security--Architecture Overview

1 核心组件 这一节主要介绍一些在Spring Security中常见且核心的Java类,它们之间的依赖,构建起了整个框架。想要理解整个架构,最起码得对这些类眼熟。 1.1 SecurityContextHolder SecurityContextHolder用于存储安全上下文(security context)的信息。当前操作的用户是谁,该用户是否已经被认证,他拥有哪些角色权限…这些都被保

Spring Security基于数据库验证流程详解

Spring Security 校验流程图 相关解释说明(认真看哦) AbstractAuthenticationProcessingFilter 抽象类 /*** 调用 #requiresAuthentication(HttpServletRequest, HttpServletResponse) 决定是否需要进行验证操作。* 如果需要验证,则会调用 #attemptAuthentica

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

Java架构师知识体认识

源码分析 常用设计模式 Proxy代理模式Factory工厂模式Singleton单例模式Delegate委派模式Strategy策略模式Prototype原型模式Template模板模式 Spring5 beans 接口实例化代理Bean操作 Context Ioc容器设计原理及高级特性Aop设计原理Factorybean与Beanfactory Transaction 声明式事物

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

Java进阶13讲__第12讲_1/2

多线程、线程池 1.  线程概念 1.1  什么是线程 1.2  线程的好处 2.   创建线程的三种方式 注意事项 2.1  继承Thread类 2.1.1 认识  2.1.2  编码实现  package cn.hdc.oop10.Thread;import org.slf4j.Logger;import org.slf4j.LoggerFactory

禁止平板,iPad长按弹出默认菜单事件

通过监控按下抬起时间差来禁止弹出事件,把以下代码写在要禁止的页面的页面加载事件里面即可     var date;document.addEventListener('touchstart', event => {date = new Date().getTime();});document.addEventListener('touchend', event => {if (new