自定义View实例(一)仿优酷菜单

一、自定义view的几种方式:

  • 1.通过Android已有的控件实现自定义效果
  • 2.通过继承View类实现自定义View
  • 3.通过继承ViewGroup类实现相应效果

二、仿优酷菜单

通过系统控件组合使用,实现仿优酷菜单的效果,效果图:
在这里插入图片描述
基本实现思路:
系统基础控件布局+view旋转动画,实现起来也是很简单,布局文件如下,每一级的菜单用RelativeLayout来写是为了方便给菜单中添加按钮

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:id="@+id/level_1"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:background="@drawable/level1"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true">
        
        <ImageView
            android:id="@+id/ic_home"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/icon_home"
            android:layout_centerInParent="true"/>
        
    </RelativeLayout>
    
    <RelativeLayout
        android:id="@+id/level_2"
        android:layout_width="180dp"
        android:layout_height="90dp"
        android:background="@drawable/level2"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true">

        <ImageView
            android:id="@+id/ic_search"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/icon_search"
            android:layout_alignParentBottom="true"
            android:layout_margin="10dp"/>
        <ImageView
            android:id="@+id/ic_menu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/icon_menu"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp"/>
        <ImageView
            android:id="@+id/ic_myyouku"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/icon_myyouku"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值