GhostView
来源:互联网 发布:3d人像建模软件 编辑:程序博客网 时间:2024/05/21 14:42
转载请注明原地址:http://blog.csdn.net/weixin_38020796/article/details/64922899
GhostView可以在不改变View的parent的情况下,在自己的Overlay里绘制另一个View。被绘制的View不会在它的Parent里绘制,因为View的visibility被设为INVISIBLE。GhostView使用被绘制的View的 render node去绘制。当GhostView为VISIBLE时,它所绘制的View为INVISIBLE;当GhostView为INVISIBLE时,它所绘制的View为VISIBLE。
public class GhostView extends View
构造方法:和被绘制的View相互持有,将被绘制的View的transition visibility设为INVISIBLE,触发View的Parent刷新。
绘制方法:使用View的updateDisplayListIfDirty获取RenderNode进行绘制
创建方法:addGhost(View , ViewGroup , Matrix) 与 addGhost(View , ViewGroup)
Example:
MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final TextView textView = (TextView) this.findViewById(R.id.textview); ColorDrawable colorDrawable = new ColorDrawable(Color.BLUE); colorDrawable.setAlpha(100); colorDrawable.setBounds(0, 0, 200, 200); textView.getOverlay().add(colorDrawable); final FrameLayout frameLayout = (FrameLayout) this.findViewById(R.id.frameLayout); frameLayout.setRight(frameLayout.getLeft() + 500); frameLayout.setBottom(frameLayout.getTop() + 200); MainActivity.this.addGhost(textView, frameLayout); this.findViewById(R.id.textview2).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { textView.setText("Change To another"); } }); } private void addGhost(View view, ViewGroup viewGroup) { try { Class ghostViewClass = Class.forName("android.view.GhostView"); Method addGhostMethod = ghostViewClass.getMethod("addGhost", View.class, ViewGroup.class, Matrix.class); View ghostView = (View) addGhostMethod.invoke(null, view, viewGroup, null); ghostView.setBackgroundColor(Color.YELLOW); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
效果:
点击CHANGE按钮,改变Button的Text,可以看到GhostView也随之更新:
将GhostView设为INVISIBLE,原来的View正常绘制:
转载请注明原地址:http://blog.csdn.net/weixin_38020796/article/details/64922899
- GhostView
- GhostView 4.2 简单破解
- mtt 有关 ghostview octave
- Android Studio 技巧之【Sublime Text Multi Selection】
- 用个ubuntu,真是步步是坑啊
- html5中表格table
- 悬镜服务器卫士上线“华为云应用超市”
- HTML和HTML5的区别
- GhostView
- makefile伪目标理解
- 面向对象继承-限制范围的拖拽
- RxJava的基本用法
- UVA 167,The Sultan's Successors
- Hadoop学习笔记之flume Nginx日志收集到HBase
- 地宫取宝 蓝桥杯试题
- Yii中where方法使用
- fopen打开文件时,路径中包含中文