您好,横屏状态下弹框没有撑满整个宽度
HuYueling opened this issue · comments
胡萝卜须 commented
如题,demo中横屏,点击在下面全屏,但是横屏状态下没有占满整个宽度
胡萝卜须 commented
还有,我在使用ConstraintLayout为layout布局时,全屏后不会在指定的targetView下,而是撑满了屏幕的高度
胡萝卜须 commented
胡萝卜须 commented
但是高度还是没找到解决办法,还是出现横屏后不显示在targetView下面
Goweii commented
提供下复现代码包括xml,我好复制进demo调试。
胡萝卜须 commented
pop弹框代码
private PopupLayer popupLayer;
if (popupLayer == null) {
popupLayer = AnyLayer.popup(findViewById(R.id.tv_show_custom_full))
.align(PopupLayer.Align.Direction.VERTICAL, PopupLayer.Align.Horizontal.CENTER, PopupLayer.Align.Vertical.BELOW, false);
popupLayer.contentView(R.layout.dialog_custom_full)
.animStyle(DialogLayer.AnimStyle.TOP)
//设置浮层外部是否拦截触摸
.outsideInterceptTouchEvent(false)
//点击外部是否消失 设为true 设为false代码没处理穿透事件
.outsideTouchedToDismiss(false)
.backgroundDimDefault()
.onInitialize(new Layer.OnInitialize() {
@Override
public void onInit(@NonNull Layer layer) {
//第一次初始化时绑定的数据
//添加背景点击事件,防止点击背景事件穿透
layer.getViewHolder().getChild()
.findViewById(R.id.anylayler_dialog_background)
.setOnClickListener(v -> {
popupLayer.dismiss();
});
PopCustomAdapter adapter = new PopCustomAdapter();
RecyclerView recyclerView = layer.requireView(R.id.pop_recycle_view);
recyclerView.setLayoutManager(new LinearLayoutManager(NormalActivity.this));
recyclerView.setAdapter(adapter);
}
});
}
if (popupLayer.isShown()) {
popupLayer.dismiss();
} else {
popupLayer.show();
}
pop弹框layout
<?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="wrap_content"
android:background="#ffffff">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/pop_recycle_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toTopOf="@+id/reset_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/pw_item_custom_layout"
tools:spanCount="3" />
<TextView
android:id="@+id/reset_layout"
android:layout_width="match_parent"
android:layout_height="44dp"
android:gravity="center"
android:text="重置"
android:textColor="#ff4919"
android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/pop_recycle_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
pop弹框适配器
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
public class PopCustomAdapter extends RecyclerView.Adapter<PopCustomAdapter.MyViewHolder> {
@NonNull
@Override
public PopCustomAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.pw_item_custom_layout, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull PopCustomAdapter.MyViewHolder holder, int position) {
holder.textView.setText("ITEM" + position);
}
//更改item个数 高度超出页面高度
@Override
public int getItemCount() {
return 10;
}
public static class MyViewHolder extends RecyclerView.ViewHolder {
private final TextView textView;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.text_view);
}
}
}
pop适配器item layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="hahha"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:gravity="center"/>
</androidx.constraintlayout.widget.ConstraintLayout>
胡萝卜须 commented
targetView
findViewById(R.id.tv_show_custom_full)是固定在顶部的,然后更改适配器的item数量后,高度太高会覆盖住targetView