Android “地图视图”拖动时速度非常慢
这是我的应用程序的架构 MainActivity只是将MainFragment加载到其容器中的骨架 MainFragment包含一个按钮,单击时添加MapsFragment MapsFragment加载mapview。它还将在其顶部显示一个自定义大小的对话框片段,并设置Android “地图视图”拖动时速度非常慢,android,android-fragments,Android,Android Fragments,这是我的应用程序的架构 MainActivity只是将MainFragment加载到其容器中的骨架 MainFragment包含一个按钮,单击时添加MapsFragment MapsFragment加载mapview。它还将在其顶部显示一个自定义大小的对话框片段,并设置WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL以使该对话框片段成为非模态 如果从onResume中启动MapsFragment mapview,它将正常工作。 然而,当拖动时,如果
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
以使该对话框片段成为非模态
如果从onResume中启动MapsFragment mapview,它将正常工作。
然而,当拖动时,如果
class MapsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_maps)
supportFragmentManager.beginTransaction()
.add(R.id.fragment_container, MainFragment.newInstance())
.commit()
}
}
//-------------------------
class MainFragment : DialogFragment(), View.OnClickListener {
companion object {
fun newInstance() = MainFragment()
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.main_fragment, container, false)
}
override fun onResume() {
super.onResume()
// if passing 0, 0, map will work fine, if passing at least 1 ms, map will be slow
object : CountDownTimer(0, 0) {
override fun onTick(millisUntilFinished: Long) {
var left = millisUntilFinished / 1000
button2.setText("$left")
}
override fun onFinish() {
activity!!.supportFragmentManager.beginTransaction()
.add(R.id.fragment_container, MapsFragment.newInstance())
.addToBackStack(null)
.commit()
}
}.start()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
button2.setOnClickListener(this)
}
override fun onClick(v: View?) {
activity!!.supportFragmentManager.beginTransaction()
.add(R.id.fragment_container, MapsFragment.newInstance())
.addToBackStack(null)
.commit()
}
}
class MapsFragment : DialogFragment() {
companion object {
fun newInstance() = MapsFragment()
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.maps_fragment, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
AddCitiesFragment.newInstance().show(activity!!.supportFragmentManager)
}
}
//-------------------------
class MainFragment : DialogFragment(), View.OnClickListener {
companion object {
fun newInstance() = MainFragment()
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.main_fragment, container, false)
}
override fun onResume() {
super.onResume()
// if passing 0, 0, map will work fine, if passing at least 1 ms, map will be slow
object : CountDownTimer(0, 0) {
override fun onTick(millisUntilFinished: Long) {
var left = millisUntilFinished / 1000
button2.setText("$left")
}
override fun onFinish() {
activity!!.supportFragmentManager.beginTransaction()
.add(R.id.fragment_container, MapsFragment.newInstance())
.addToBackStack(null)
.commit()
}
}.start()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
button2.setOnClickListener(this)
}
override fun onClick(v: View?) {
activity!!.supportFragmentManager.beginTransaction()
.add(R.id.fragment_container, MapsFragment.newInstance())
.addToBackStack(null)
.commit()
}
}
class MapsFragment : DialogFragment() {
companion object {
fun newInstance() = MapsFragment()
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.maps_fragment, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
AddCitiesFragment.newInstance().show(activity!!.supportFragmentManager)
}
}