继承PositionPopupVIew后布局的宽度展示异常
VamPeng opened this issue · 1 comments
VamPeng commented
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,这个貌似不太正常。