欢迎光临
我们一直在努力

直播源码网站,点击分类调起菜单栏并弹出

直播源码网站,点击分类调起菜单栏并弹出实现的相关代码

首先,声明一个类继承自PopupWindow (这里你也可以在使用的activity/Fragment中使用new PopupWindow方式来实现)

 


public class DevicePopWindow extends PopupWindow {
    public DevicePopWindow(){
        super(ViewGroup.layoutParams.wrap_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        //这里要注意设置setOutsideTouchable之前要设置 setBackgroundDrawable()
        //否则点击外部无法关闭pop
        setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        setOutsideTouchable(true);
        //获取焦点设置为true 这样再次点击菜单时 就隐藏菜单
        setFocusable(true);
        View inflate = LayoutInflater.from(BaseApplication.getAppContext()).inflate(R.layout.pop_window_device, null);
        setContentView(inflate);
        //设置窗口进入和退出的动画
        setAnimationStyle(R.style.pop_add);
    }
}
R.layout.pop_window_device.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >
    <LinearLayout
        android:padding="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:background="@drawable/shape_device_pop"
        android:orientation="vertical"
        android:paddingBottom="20dp"
        android:paddingEnd="16dp"
        android:paddingStart="26dp"
        android:paddingTop="20dp">
        <TextView
            android:id="@+id/tv_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="发起群聊"
            android:textColor="@color/colorBlack"
            android:textSize="16sp"/>
        <TextView
            android:id="@+id/tv_2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="添加朋友"
            android:textColor="@color/colorBlack"
            android:textSize="16sp"/>
        <TextView
            android:id="@+id/tv_3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="扫一扫"
            android:textColor="@color/colorBlack"
            android:textSize="16sp"/>
        <TextView
            android:id="@+id/tv_4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="收付款"
            android:textColor="@color/colorBlack"
            android:textSize="16sp"/>
        <TextView
            android:id="@+id/tv_5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:text="帮助与反馈"
            android:textColor="@color/colorBlack"
            android:textSize="16sp"/>
    </LinearLayout>
</LinearLayout>

 

R.style.pop_add 样式

 


  <style name="pop_add" parent="android:Animation">
    <item name="android:windowEnterAnimation">@anim/pop_add_show</item>
    <item name="android:windowExitAnimation">@anim/pop_add_hide</item>
</style>
@anim/pop_add_show.xml pop弹出动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="300"
        android:fromAlpha="0.0"
        android:toAlpha="1.0"/>
    <scale
        android:duration="300"
        android:fromXScale="0"
        android:fromYScale="0"
        android:interpolator="@android:anim/decelerate_interpolator"
        android:pivotX="85%"
        android:pivotY="0%"
        android:toXScale="1.0"
        android:toYScale="1.0"/>
</set>
@anim/pop_add_hide.xml pop隐藏动画
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
    android:duration="300"
    android:fromAlpha="1.0"
    android:toAlpha="0.0"/>
<scale
    android:duration="300"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:pivotX="85%"
    android:pivotY="0%"
    android:toXScale="0"
    android:toYScale="0"/>
</set>

 

 

在我们的页面中进行使用

 


class DeviceFragment : Fragment() {
    lateinit var devicePopWindow: DevicePopWindow
    lateinit var rootView: View
    lateinit var successView:View
   
    override fun onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState): View {
        rootView =  inflater.inflate(R.layout.base_device_fragment_layout,container,false)
        initView(inflater)
        initListener()
        return rootView
    }
    fun initView(inflate: View) {
        devicePopWindow = DevicePopWindow()
    }
 
     fun initListener() {
        rootView.findViewById<ImageView>(R.id.device_head_add).setOnClickListener {
                //设置pop显示位置
                devicePopWindow.showAsDropDown(it,-150,10)
                backgroundAlpha(0.8f)
        }
        //pop消失的监听
        devicePopWindow.setOnDismissListener {
            backgroundAlpha(1.0f)
        }
    }
    /**
     * 此方法用于改变背景的透明度,从而达到“变暗”的效果
     */
    private fun backgroundAlpha(bgAlpha: Float) {
        val lp: WindowManager.LayoutParams = activity!!.window.attributes
        // 0.0-1.0
        lp.alpha = bgAlpha
        activity!!.window.attributes = lp
        // everything behind this window will be dimmed.
        // 此方法用来设置浮动层,防止部分手机变暗无效
        activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
    }
}

 

以上就是直播源码网站,点击分类调起菜单栏并弹出实现的相关代码, 更多内容欢迎关注之后的文章

 

  • 海报
海报图正在生成中...
赞(0) 打赏
声明:
1、本博客不从事任何主机及服务器租赁业务,不参与任何交易,也绝非中介。博客内容仅记录博主个人感兴趣的服务器测评结果及一些服务器相关的优惠活动,信息均摘自网络或来自服务商主动提供;所以对本博客提及的内容不作直接、间接、法定、约定的保证,博客内容也不具备任何参考价值及引导作用,访问者需自行甄别。
2、访问本博客请务必遵守有关互联网的相关法律、规定与规则;不能利用本博客所提及的内容从事任何违法、违规操作;否则造成的一切后果由访问者自行承担。
3、未成年人及不能独立承担法律责任的个人及群体请勿访问本博客。
4、一旦您访问本博客,即表示您已经知晓并接受了以上声明通告。
文章名称:《直播源码网站,点击分类调起菜单栏并弹出》
文章链接:https://www.456zj.com/9911.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址