XPopup
XPopup copied to clipboard
继承PositionPopupVIew后布局的宽度展示异常
XPopup版本 2.9.19
手机系统和型号 一加8t
*描述你的问题 继承 PositionPopupView的时候,弹框show的宽度不会根据 给的layout.xml布局的宽度来决定:
popupview代码很简单:
class RangePopV2(context: Context) : FullScreenPopupView(context) {
override fun getImplLayoutId(): Int {
return R.layout.drug_pop_date_range
}
fun show(watchView: View) {
val intArray = intArrayOf(0, 0)
watchView.getLocationOnScreen(intArray)
val watchViewHeight = watchView.height
val watchViewLocationY = intArray[1]
popupInfo.offsetY = watchViewLocationY + watchViewHeight + 8.dp().toInt()
show()
}
companion object {
fun show(
context: Context,
watchView: View,
){
val pop = RangePopV2(context)
XPopup.Builder(context)
.asCustom(pop)
pop.show(watchView)
}
}
}
layout.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="match_parent"
android:background="@color/white"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="积分时间"
android:textColor="@color/txt_gray_dark"
android:textSize="16sp"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@color/white">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:text="开始时间:"
android:textColor="#ff969799"
android:textSize="16sp" />
<TextView
android:id="@+id/drugTvTimeStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginEnd="8dp"
android:drawableEnd="@drawable/ic_arrow_right_64"
android:drawablePadding="8dp"
android:hint="请选择"
android:paddingVertical="8dp"
android:textColor="#ff969799"
android:textColorHint="#ff969799"
android:textSize="16sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="200dp"
android:background="@color/white"
android:paddingHorizontal="16dp"
android:paddingTop="8dp"
android:paddingBottom="24dp">
<TextView
android:id="@+id/drugTvReset"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_weight="1"
android:gravity="center"
android:paddingVertical="8dp"
android:text="重置"
android:textColor="@color/txt_black"
android:textSize="16sp" />
<TextView
android:id="@+id/drugTvConfirm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:gravity="center"
android:paddingVertical="8dp"
android:text="确认"
android:textColor="@color/txt_main"
android:textSize="16sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#33000000" />
</LinearLayout>
我发现弹框的视图宽度会根据我layout中第一个子view(TextView)的宽度而改变,当第一个子view的宽度设置为wrap,那弹框就会很窄,窄到刚好展示完第一个子view,当第一个子view宽度设置为match,那弹框也会变成match,这个貌似不太正常。
我也同样出现这个问题,不知道是不是我写的有问题
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true">
<TextView
android:id="@+id/tvNotificationMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="10dp"
android:paddingVertical="5dp"
android:singleLine="true"
android:scrollHorizontally="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="start"
android:background="@color/notice_ware_bg"
android:textColor="@color/title_text_alert_dark"
android:textSize="@dimen/tv_text_size_2"
android:text=""
tools:text="设备存在故障,点击查看详情 >>" />
</LinearLayout>
</layout>
val notification_popwin = NotificationMsgPopwin(requireContext(), "错误错误点击试试")
notification_popwin.setAction(NotificationMsgPopwin.Companion.NOTIFICATION_ACTION_TYPE.DISMISS)
XPopup.Builder(requireContext())
.isDestroyOnDismiss(true)
.popupAnimation(PopupAnimation.TranslateFromTop)
.isClickThrough(true)
.dismissOnBackPressed(false)
.dismissOnTouchOutside(false)
.hasShadowBg(false)
.hasBlurBg(false)
.atView(view)
.asCustom(notification_popwin)
.show()