成都创新互联网站制作重庆分公司

Android实现Z轴布局效果-创新互联

如果需要在布局中创造一个层叠的概念,那么使用Android系统中的ViewGroup是不够的,但是可以通过改变ViewGroup的绘制顺序实现

创新互联于2013年创立,先为历城等服务建站,历城等地企业,进行企业商务咨询服务。为历城企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

Android实现Z轴布局效果

代码下载

继承自FrameLayout

FrameLayout已经帮我们实现了子View的measure和layout过程,我们只需在它的基础上改变绘制顺序即可

自定义LayoutParams

layoutParams的作用是向父布局请求布局参数(MeasureSpec),这个参数会在View inflate时添加到布局中,我们如果使用LayoutParams将会得到很大的方便

// 这里继承FrameLayout的LayoutParams即可
public static class LayoutParams extends FrameLayout.LayoutParams {

 public final static int DEFAULT_ZORDER = 1;

 public int zOrder;

 public LayoutParams(@NonNull Context c, @Nullable AttributeSet attrs) {
  super(c, attrs);
  TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.ZOrderLayout);
  zOrder = a.getInt(R.styleable.ZOrderLayout_layout_zorder, DEFAULT_ZORDER);
  a.recycle();
 }
}

当前名称:Android实现Z轴布局效果-创新互联
网站网址:http://cxhlcq.com/article/cdgpod.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部