[原创]android framelayout&n…
16lz
2021-01-26
这个类是我实际做android时候做activity内的浮动层效果时封装的类 如果一个界面有多个浮动层可以简单复制这个类快速做出多个浮动层来
public class PlayerHeader extends FrameLayout { private static final String LOG_TAG = MainActivity.class.getName();
public PlayerHeader(Context context) { super(context); mContext = context; }
public PlayerHeader(Context context, AttributeSet attrs) { super(context, attrs); headerRoot = null; mContext = context; }
public PlayerHeader(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } // 这里只调用一次,使用这个函数创建一个布局到framelayout public void init(ViewGroup anchorView, VideoView videoview) { //添加浮动层的framelayout mAnchor = anchorView; // init header ----------------- LayoutInflater inflate = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); //新建的层放在framelayout顶部 FrameLayout.LayoutParams tlp1 = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP);
// init header headerRoot = inflate.inflate(R.layout.media_controler_header, null); //这个只是示范代码,在这里记录所有控件的句柄 bTitle = (TextView) headerRoot.findViewById(R.id.video_title); bIcon = (ImageView) headerRoot.findViewById(R.id.channel_icon); mAnchor.addView(headerRoot, tlp1);
hide();
} // 控制板显示/ public void show() {
headerRoot.setVisibility(VISIBLE); mShowing = true; }
public void hide() { headerRoot.setVisibility(INVISIBLE); mShowing = false; } }
使用方法 playerHeader= new PlayerHeader (this); //找到要添加浮动层的framelayout playerHeader.init((FrameLayout) findViewById(R.id.ff), player); playerHeader.show()//显示 playerHeader.hide()//显示
public class PlayerHeader extends FrameLayout { private static final String LOG_TAG = MainActivity.class.getName();
public PlayerHeader(Context context) { super(context); mContext = context; }
public PlayerHeader(Context context, AttributeSet attrs) { super(context, attrs); headerRoot = null; mContext = context; }
public PlayerHeader(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } // 这里只调用一次,使用这个函数创建一个布局到framelayout public void init(ViewGroup anchorView, VideoView videoview) { //添加浮动层的framelayout mAnchor = anchorView; // init header ----------------- LayoutInflater inflate = (LayoutInflater) mContext .getSystemService(Context.LAYOUT_INFLATER_SERVICE); //新建的层放在framelayout顶部 FrameLayout.LayoutParams tlp1 = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.TOP);
// init header headerRoot = inflate.inflate(R.layout.media_controler_header, null); //这个只是示范代码,在这里记录所有控件的句柄 bTitle = (TextView) headerRoot.findViewById(R.id.video_title); bIcon = (ImageView) headerRoot.findViewById(R.id.channel_icon); mAnchor.addView(headerRoot, tlp1);
hide();
} // 控制板显示/ public void show() {
headerRoot.setVisibility(VISIBLE); mShowing = true; }
public void hide() { headerRoot.setVisibility(INVISIBLE); mShowing = false; } }
使用方法 playerHeader= new PlayerHeader (this); //找到要添加浮动层的framelayout playerHeader.init((FrameLayout) findViewById(R.id.ff), player); playerHeader.show()//显示 playerHeader.hide()//显示
更多相关文章
- Android设备双屏异显
- android 布局相关
- Android(安卓)的输入框(EditText)设置密码可见/不可见切换的最简
- Android(安卓)中添加水平线和垂直线方法总结
- Android(安卓)Zxing 添加闪光灯功能
- android圆形图片显示ImageView超简单控件
- Android开发错误:Error:” ” is not translated in “en” (Engl
- ActionBar的Splite模式
- Wifi模块—源码分析Wifi初始化(Android(安卓)P)