一、自定义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"