【发布时间】:2019-01-24 10:08:06
【问题描述】:
我正在尝试设置类似于旧 Facebook 评论部分的弹出窗口。
圆角对话框,但我遇到了对话框的size of dialog box 和showatlocation 的问题。
当我在不同的手机上尝试这段代码时:
val display = windowManager.defaultDisplay
val size = Point()
display.getSize(size)
val popupWindow = PopupWindow(customView, size.x-30, size.y-300, true)
popupWindow.showAtLocation(linearLayout1, Gravity.CENTER, -3, 100)
popupWindow.setAnimationStyle(R.style.PopupAnimation)
Xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/dialog_bg"
android:gravity="center"
android:orientation="vertical"
android:padding="10px">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation="horizontal">
<android.support.v7.widget.RecyclerView
android:id="@+id/popup_rcv"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/new_comment_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Please enter Comment" />
<Button
android:id="@+id/comment_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
</LinearLayout>
//来自Source的动画
另外,当我将 .showAtLocation 更改为其他数字时,我的动画也会禁用
Lenovo K8 Note 上的输出:
在 K8 中,如果我更改为另一个值,则弹出窗口的位置会发生变化。
在此先感谢您。
【问题讨论】:
-
为什么不直接使用对话框来代替它会产生你想要的效果,除非你想要动画。这是提示用户反馈的更简单的方法。这样您就不必担心它会显示在哪里,而且您可以将自定义样式添加到对话框stackoverflow.com/questions/12351330/…
标签: android kotlin popupwindow