goweii / AnyLayer

Android稳定高效的浮层创建管理框架
https://github.com/goweii/AnyLayer
Apache License 2.0
993 stars 114 forks source link

contentView(layoutInflater.inflate(R.layout.item,null)) 全屏问题 #27

Closed GravesMrma closed 3 years ago

GravesMrma commented 4 years ago

为什么contentView放View对象 就直接变成了全屏 放resourcesId 就不会全屏

AnyLayer .dialog(this) .contentView(R.layout.layout_land) 非全屏

AnyLayer .dialog(this) .contentView(mView) 全屏

goweii commented 4 years ago

你贴下布局文件和转view的代码

GravesMrma commented 4 years ago

<?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">

<ImageView
    android:id="@+id/ivImage"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="#ff8020"
    app:layout_constraintTop_toTopOf="parent" />

<TextView
    android:id="@+id/tvText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff"
    android:gravity="center"
    android:padding="20dp"
    android:text="文字"
    app:layout_constraintTop_toBottomOf="@id/ivImage" />

</androidx.constraintlayout.widget.ConstraintLayout>

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    tvText1.setOnClickListener {
        var view = layoutInflater.inflate(R.layout.item_dialog, null)
        AnyLayer
            .dialog(this)
            .contentView(view)
            .gravity(Gravity.BOTTOM)
            .backgroundColorInt(ContextCompat.getColor(this, R.color.clarity_30))
            .cancelableOnTouchOutside(true)
            .outsideInterceptTouchEvent(true)
            .show()
    }
}

}

goweii commented 4 years ago

你时说高度全屏了吗?这两种方式引入contentView的区别就是会不会带有跟布局指定的layout_开头的属性,当跟布局没有layoutParams时会指定宽高为wrap_content,具体效果和根布局的测量方式有关系,你得看下ConstraintLayout 的onMearure方法,或者换一个根布局。

GravesMrma commented 4 years ago

我今天看了一下DialogLayer里面的代码 我改了一点代码 解决了这个问题 在DialogLayer的474行 不知道会不会引起别的问题 希望你看一下

protected void initContent() { getViewHolder().getContent().setClickable(true); ViewGroup.LayoutParams layoutParams = getViewHolder().getContent().getLayoutParams(); FrameLayout.LayoutParams contentParams; if (layoutParams == null) { contentParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); } else if (layoutParams instanceof FrameLayout.LayoutParams) { // contentParams = (FrameLayout.LayoutParams) layoutParams; 注释这行代码 改为下面这行代码 可以暂时解决全屏高度问题 contentParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } else { contentParams = new FrameLayout.LayoutParams(layoutParams.width, layoutParams.height); } if (getConfig().mGravity != -1) { contentParams.gravity = getConfig().mGravity; } getViewHolder().getContent().setLayoutParams(contentParams); if (getConfig().mAsStatusBarViewId > 0) { View statusBar = getViewHolder().getContent().findViewById(getConfig().mAsStatusBarViewId); if (statusBar != null) { ViewGroup.LayoutParams params = statusBar.getLayoutParams(); params.height = Utils.getStatusBarHeight(getActivity()); statusBar.setLayoutParams(params); statusBar.setVisibility(View.VISIBLE); } } }

goweii commented 4 years ago

我应该定位到问题了,不是这个原因,明天发版本修复。

goweii commented 4 years ago

最新版已发

GravesMrma commented 3 years ago

@goweii AnyLayer.popup(menuView) .align(PopupLayer.Align.Direction.VERTICAL, PopupLayer.Align.Horizontal.CENTER, PopupLayer.Align.Vertical.BELOW, true) .outsideInterceptTouchEvent(false) .backgroundDimDefault() .outsideTouchedToDismiss(false) .contentView(FilterMenuView(this@EducationCategoryActivity)) .contentAnimator(object : Layer.AnimatorCreator { override fun createInAnimator(content: View): Animator? { return AnimatorHelper.createTopInAnim(content) } override fun createOutAnimator(content: View): Animator? { return AnimatorHelper.createTopOutAnim(content) } }) 出现了同样的问题 .contentView() 这个方法里面如果传View 会导致高宽失效 如果传R.layout.item 则是正常的

goweii commented 3 years ago

@goweii AnyLayer.popup(menuView) .align(PopupLayer.Align.Direction.VERTICAL, PopupLayer.Align.Horizontal.CENTER, PopupLayer.Align.Vertical.BELOW, true) .outsideInterceptTouchEvent(false) .backgroundDimDefault() .outsideTouchedToDismiss(false) .contentView(FilterMenuView(this@EducationCategoryActivity)) .contentAnimator(object : Layer.AnimatorCreator { override fun createInAnimator(content: View): Animator? { return AnimatorHelper.createTopInAnim(content) } override fun createOutAnimator(content: View): Animator? { return AnimatorHelper.createTopOutAnim(content) } }) 出现了同样的问题 .contentView() 这个方法里面如果传View 会导致高宽失效 如果传R.layout.item 则是正常的

你在哪个版本出现的?升级最新的试下。

GravesMrma commented 3 years ago

我用的是 4.0.0-beta1 我用老版本的 倒没问题 就是升级之后才出现的这个问题

goweii commented 3 years ago

好的,你可以先用正式版,beta版不稳定,抽空修复。

GravesMrma commented 3 years ago

正式版和beta版 有些区别 我目前还是用的bate版 有问题再说吧

GravesMrma commented 3 years ago

谢谢你贡献出这么优秀的一个框架

goweii commented 3 years ago

我用的是 4.0.0-beta1 我用老版本的 倒没问题 就是升级之后才出现的这个问题

我刚试了下,在4.0.0-beta1没有复现这个问题,你具体是怎么出现的,可以贴下代码吗?