小编fai*_*iry的帖子

如何修复框架布局中的内存泄漏问题?

我在我的 android 应用程序中使用 leakcanary 并且它检测到FrameLayout Leaked。但我无法找到或解决这个问题,

我该如何修复这个泄漏?参考我的泄漏金丝雀报告。 FrameLayout 泄露

 ????
    ? GC Root: System class
    ?
    ?? leakcanary.internal.InternalLeakCanary class
    ?    Leaking: NO (MainActivity? is not leaking and a class is never leaking)
    ?    ? static InternalLeakCanary.resumedActivity
    ?? com.android.zigmaster.MainActivity instance
    ?    Leaking: NO (MapViewFragment? is not leaking and Activity#mDestroyed
    ?    is false)
    ?    mApplication instance of com.android.zigmaster.MyApplication
    ?    mBase instance of androidx.appcompat.view.ContextThemeWrapper
    ?    ? ComponentActivity.mActivityResultRegistry
    ?? androidx.activity.ComponentActivity$2 instance
    ?    Leaking: NO (MapViewFragment? is not leaking)
    ?    Anonymous subclass of …
Run Code Online (Sandbox Code Playgroud)

android google-maps google-maps-android-api-2 leakcanary

6
推荐指数
1
解决办法
381
查看次数

如何在 SupportMapFragment 中使用视图绑定?

如何在 SupportMapFragment 中使用视图绑定?参考我的代码

我在布局中有一个地图片段,我想在片段中使用视图绑定。

val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment

LZ需要解决方案..

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.SupportMapFragment
import com.zeddigital.zigmaster.R
import com.zeddigital.zigmaster.databinding.FragmentHomeBinding

class HomeFragment : Fragment() {
    private lateinit var mMap: GoogleMap

    private var binding : FragmentHomeBinding ?=null
    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
    ): View {
        binding = FragmentHomeBinding.inflate(inflater)

        // binding.myTextView.text = "sample"

        val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
        mapFragment.getMapAsync { googleMap ->

        }

        return binding!!.root
    }

    override fun …
Run Code Online (Sandbox Code Playgroud)

android android-viewbinding

5
推荐指数
2
解决办法
662
查看次数

如何在自定义对话框布局中使用视图绑定?

我在自定义对话框布局中实现视图绑定时遇到问题。是否可以?

 private fun showCustomDialog(title: String) {
    val dialog = Dialog(activity)
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
    dialog.setCancelable(false)

    dialog.setContentView(R.layout.custom_layout)

    val body = dialog.findViewById(R.id.body) as TextView
    body.text = title

    val noBtn = dialog.findViewById(R.id.noBtn) as TextView
    yesBtn.setOnClickListener {
        dialog.dismiss()
    }

    val yesBtn = dialog.findViewById(R.id.yesBtn) as Button
    noBtn.setOnClickListener { dialog.dismiss() }
    dialog.show()

}
Run Code Online (Sandbox Code Playgroud)

android android-viewbinding

1
推荐指数
2
解决办法
1108
查看次数