为了账号安全,请及时绑定邮箱和手机立即绑定
  • 鸿翔?
    查看全部
  • 这里为什么需要再次获取mRadius值?
    查看全部
  • 喜欢这个老师讲课
    查看全部
  • 定位item(定位每个子菜单的位置) (2)这是一个复杂的过程,首先通过图算出子菜单View的相对于父容器左边和顶部的宽和高,实际上就是对应layout(int l, int t, int r, int b)的l和t这两个参数 但是要注意由于菜单位置不同,l和t的计算值会不同 //逐个定位每个子菜单View的位置 for (int i = 0; i < count - 1; i++){ View child = getChildAt(i+1); //因为主按钮是0,所以子菜单从1开始到count-1 int cl = (int) (mRadius * Math.sin(Math.PI/2/(count-2)*i)); //注意第一个子菜单的sin角度为0 int ct = (int) (mRadius * Math.cos(Math.PI/2/(count-2)*i)); //每个子菜单View本身的宽和高 int cWidth = child.getMeasuredWidth(); int cHeight = child.getMeasuredHeight(); //如果菜单位于底部(左下,右下),相对于顶部的参数ct就需要调整 if (mPosition == Position.LEFT_BOTTOM || mPosition == Position.RIGHT_BOTTOM){ ct = getMeasuredHeight() - cHeight - ct; } //如果菜单位于右部(右下,右上),相对于左边的参数cl就需要调整 if (mPosition == Position.RIGHT_BOTTOM || mPosition == Position.RIGHT_TOP){ cl = getMeasuredWidth() - cWidth - cl; } child.layout(cl, ct, cl+cWidth, ct+cHeight); }
    查看全部
    1 采集 收起 来源:定位Item

    2018-03-22

  • 自定义属性 2)在ArcMenu构造函数中获取属性值 TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ArcMenu, defStyleAttr, 0); int position = ta.getInt(R.styleable.ArcMenu_position, POS_RIGHT_BOTTOM); //获取在layout布局中指定的位置属性,默认是右下 mRadius = (int) ta.getDimension(R.styleable.ArcMenu_radius, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics())); //获取在layout布局中指定的半径属性值,默认是100dp;第二个参数是将100dp转换成像素值 3.为子菜单项设置点击回调接口 public interface OnMenuItemClickListener { //声明要实现的接口方法 void onClick(View view, int pos); } private OnMenuItemClickListener mMenuItemClickListener; //设置回调的接口 public void SetOnMenuItemClickListener(OnMenuItemClickListener mListener) { this.mMenuItemClickListener = mListener; }
    查看全部
  • 自定义属性 1.定义两个自定义属性:主按钮位置、子菜单半径 2.自定义属性的使用步骤: (1)在attr.xml中定义这两个属性 <resources> <attr name="position" > <enum name="left_top" value="0" /> <enum name="left_bottom" value="1" /> <enum name="right_top" value="2" /> <enum name="right_bottom" value="3" /> </attr> <attr name="radius" format="dimension" /> <declare-styleable name="ArcMenu"> <attr name="position" /> <attr name="radius" /> </declare-styleable> (2)在layout中使用 注意在AS中需要按如下添加命名空间 xmlns:zhangxt4="http://schemas.android.com/apk/res-auto" //添加命名空间 <com.zhangxt4.satellitemenu.view.ArcMenu zhangxt4:position="right_bottom" zhangxt4:radius="150dp"> (3)在自定义控件中读取layout中指定的属性值 自定义控件为public class ArcMenu extends ViewGroup { 1)首先定义连个变量用来表示前面的两个属性 //菜单位置的枚举类 public enum Position { LEFT_TOP, LEFT_BOTTOM, RIGHT_TOP, RIGHT_BOTTOM } private Position mPosition = Position.RIGHT_BOTTOM; //默认是右下方 private int mRadius; //子菜单的半径 2)在ArcMenu构造函数中获取属性值(如图) 根据获取的属性值来设置主按钮位置和半径 3.为子菜单项设置回调点击事件
    查看全部
  • 记录一下
    查看全部
  • 有疑问如何提问呢?
    查看全部
  • satellite menu卫星式菜单第三方
    查看全部
  • 1.自定义属性<br> a、attr.xml<br> b、在布局文件中使用 c、在自定义控件中进行读取
    查看全部
  • 简单的设置属性方法
    查看全部
  • 定位卫星
    查看全部
  • 自定义属性: a. attr.xml b.在布局文件中使用 c.在自定义控件中进行读取
    查看全部
  • 自定义控件
    查看全部
  • 代码中使用自定义属性
    查看全部
首页上一页123456下一页尾页

举报

0/150
提交
取消
课程须知
本课程需要大家对Android的了解要达到小成的境界: 1、掌握自定义控件的流程 2、熟悉常用的控件以及API 3、对传统View动画有一定的了解。
老师告诉你能学到什么?
通过本课程,你将学到: 1、自定义属性的声明和获取以及应用 2、按需求定制的自定义控件的测量和布局 3、对传统View动画的进一步理解

微信扫码,参与3人拼团

意见反馈 帮助中心 APP下载
官方微信
友情提示:

您好,此课程属于迁移课程,您已购买该课程,无需重复购买,感谢您对慕课网的支持!