【问题标题】:How to show custom floating view like popup menu?如何显示自定义浮动视图,如弹出菜单?
【发布时间】:2021-07-11 10:22:31
【问题描述】:

如何在android中创建一个弹出视图?上下文菜单仅显示项目列表。但我试图改为显示自定义布局。我搜索了互联网,但一无所获。可能是我无法表达我想要做什么!

我的应用中有一个底部栏。其中有一些按钮。我希望当我单击特定按钮时,会在该视图附近显示一个弹出窗口。就像上下文菜单,但布局不同。有可能吗?

我想要这样的东西。

【问题讨论】:

  • 您是否尝试过使用PopUpWindow
  • 这样的东西并不完全是一个弹出窗口,它只是一个自定义视图,当你让它可见时它会显示在视图的顶部

标签: android kotlin android-layout contextmenu


【解决方案1】:

你可以这样做

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:background="@color/black">


    </LinearLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:background="@color/white"/>

</androidx.constraintlayout.widget.ConstraintLayout>

主要思想是最后一项与上一项重叠。您只需要实现回收站视图并将其方向设置为从左到右。您还可以像普通视图一样启用和禁用可见性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-15
    • 2011-02-28
    • 1970-01-01
    相关资源
    最近更新 更多