У меня есть макет ограничения внутри прокрутки. и внутри этого макета ограничения у меня есть фрагмент карты поддержки.
Я пытаюсь найти то, что заставляет мое приложение медленно рендериться. требуется около 1,5 секунды, чтобы показать фрагмент, содержащий карту (фрагмент карты поддержки). Я имею в виду, что когда я заменяю фрагмент A на фрагмент B (который имеет карту), это займет слишком много времени, через 1-2 секунды, тогда фрагмент B появится на экране.
вот мой xml
<ScrollView 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="match_parent"
android:background="@android:color/white" android:id="@+id/scrollView_event_detail">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context=".Fragments.Reusable.EventDetailFragment"
android:id="@+id/constraintLayout_event_detail_destination">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp" tools:src="@tools:sample/backgrounds/scenic[12]"
android:id="@+id/imageView_event_detail_blurred_poster"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:scaleType="centerCrop" app:layout_constraintDimensionRatio="1:1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="0dp" tools:src="@tools:sample/backgrounds/scenic[12]"
android:id="@+id/imageView_event_detail_poster"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintDimensionRatio="1:1"
android:scaleType="fitCenter"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content" android:id="@+id/textView_event_detail_event_title"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/imageView_event_detail_blurred_poster"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="16dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="16dp" android:maxLines="2"
android:textSize="18sp" tools:text="Kajian Bulanan: Memahami Adab Para Penuntut Ilmu"/>
<View
android:layout_width="0dp"
android:layout_height="0.5dp" android:id="@+id/line1_view_event_detail" android:background="#696C79"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/textView_event_detail_event_title"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="16dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="16dp"/>
<Button
android:text="Hadir"
android:layout_width="0dp"
android:layout_height="50dp" android:id="@+id/button_search_event_search"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/line1_view_event_detail"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="16dp"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="16dp"
android:background="@drawable/rounded_button"
android:textColor="#ffffff"/>
<View
android:layout_width="0dp"
android:layout_height="0.5dp" android:id="@+id/line2_view_event_detail" android:background="#696C79"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/button_search_event_search"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="16dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="16dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_date_time"
android:id="@+id/imageView_event_detail_icon_dateTime"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="16dp"
app:layout_constraintTop_toBottomOf="@+id/line2_view_event_detail" android:layout_marginTop="16dp"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/textView_event_detail_date_label"
app:layout_constraintTop_toTopOf="@+id/imageView_event_detail_icon_dateTime"
app:layout_constraintBottom_toBottomOf="@+id/imageView_event_detail_icon_dateTime"
app:layout_constraintStart_toEndOf="@+id/imageView_event_detail_icon_dateTime"
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="16dp" tools:text="Selasa, 23 Desember 2018 - Rabu, 24 Desember 2018"
android:maxLines="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/textView_event_detail_time_label"
app:layout_constraintTop_toBottomOf="@+id/textView_event_detail_date_label"
app:layout_constraintStart_toStartOf="@+id/textView_event_detail_date_label"
tools:text="17.00 - 21.00 WIB"
android:maxLines="1"
android:layout_marginTop="4dp" android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_place"
android:id="@+id/imageView_event_detail_icon_address"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="16dp"
app:layout_constraintTop_toBottomOf="@+id/textView_event_detail_time_label"
android:layout_marginTop="16dp"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/textView_event_detail_venue_label"
app:layout_constraintTop_toTopOf="@+id/imageView_event_detail_icon_address"
app:layout_constraintBottom_toBottomOf="@+id/imageView_event_detail_icon_address"
app:layout_constraintStart_toEndOf="@+id/imageView_event_detail_icon_address"
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="16dp" tools:text="Universitas Gadjah Mada"
android:maxLines="1"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/textView_event_detail_address_label"
app:layout_constraintTop_toBottomOf="@+id/textView_event_detail_venue_label"
app:layout_constraintStart_toStartOf="@+id/textView_event_detail_venue_label"
tools:text="Jalan Grafika no.1. Sinduadi Sleman. Yogyakarta"
android:maxLines="1"
android:layout_marginTop="4dp" android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_person"
android:id="@+id/imageView_event_detail_icon_speaker"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="16dp"
app:layout_constraintTop_toBottomOf="@+id/textView_event_detail_address_label" android:layout_marginTop="16dp"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/textView_event_detail_speaker_label"
app:layout_constraintTop_toTopOf="@+id/imageView_event_detail_icon_speaker"
app:layout_constraintBottom_toBottomOf="@+id/imageView_event_detail_icon_speaker"
app:layout_constraintStart_toEndOf="@+id/imageView_event_detail_icon_speaker"
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="16dp" tools:text="Pembicara: Ustadz Khalid Basalamah"
android:maxLines="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_monetization"
android:id="@+id/imageView_event_detail_icon_price"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="16dp"
app:layout_constraintTop_toBottomOf="@+id/textView_event_detail_speaker_label"
android:layout_marginTop="16dp"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/textView_event_detail_price_label"
app:layout_constraintTop_toTopOf="@+id/imageView_event_detail_icon_price"
app:layout_constraintBottom_toBottomOf="@+id/imageView_event_detail_icon_price"
app:layout_constraintStart_toEndOf="@+id/imageView_event_detail_icon_price"
android:layout_marginStart="8dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="16dp" tools:text="Rp 50.000"
android:maxLines="1"/>
<View
android:layout_width="0dp"
android:layout_height="0.5dp" android:id="@+id/line3_view_event_detail" android:background="#696C79"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/textView_event_detail_price_label"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="16dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="16dp"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/textView_event_detail_description_snippet_label"
app:layout_constraintTop_toTopOf="@+id/line3_view_event_detail"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="16dp" tools:text="Kajian akan membahas kitab Riyadush Shalihin Bab 3"
android:maxLines="2"/>
<TextView
android:text="Baca Selengkapnya"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView_button_read_more"
app:layout_constraintTop_toBottomOf="@+id/textView_event_detail_description_snippet_label"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:clickable="true"
android:focusable="true" android:textColor="#2196F3"/>
<View
android:layout_width="0dp"
android:layout_height="0.5dp" android:id="@+id/line4_view_event_detail" android:background="#696C79"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/textView_button_read_more"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="16dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="16dp"/>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="0dp"
android:layout_height="180dp"
android:id="@+id/map_event_detail"
tools:context=".Activities.MainActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@+id/line4_view_event_detail"
android:layout_marginStart="16dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:text="Peta Ke Lokasi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView_button_map_more"
app:layout_constraintTop_toBottomOf="@+id/map_event_detail"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:clickable="true"
android:focusable="true" android:textColor="#2196F3"/>
<View
android:layout_width="0dp"
android:layout_height="0.5dp" android:id="@+id/line5_view_event_detail" android:background="#696C79"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@+id/textView_button_map_more"
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="16dp"
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="16dp"/>
<TextView
android:text="Penyelenggara"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView_event_detail_organizer_tag"
app:layout_constraintTop_toBottomOf="@+id/line5_view_event_detail"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"/>
<TextView
android:text="Masjid Nurul Iman"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView_event_detail_organizer_label"
app:layout_constraintTop_toBottomOf="@+id/textView_event_detail_organizer_tag"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Я пытался закомментировать все коды в моем onCreateView. так что этот фрагмент ничего не сделает. и все же, мое приложение медленно отображается при показе этого фрагмента.
но когда я пытаюсь удалить фрагмент карты поддержки из моего xml, я имею в виду эту часть:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="0dp"
android:layout_height="180dp"
android:id="@+id/map_event_detail"
tools:context=".Activities.MainActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_marginTop="24dp"
app:layout_constraintTop_toBottomOf="@+id/line4_view_event_detail"
android:layout_marginStart="16dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"/>
это ускорит рендеринг моего приложения. так почему это произошло или есть альтернативы, чтобы решить это?
Я имею в виду, чтобы показать карту в макете ограничений внутри вида прокрутки?
вот мой код:
class EventDetailFragment : Fragment() {
lateinit var titleTextView: TextView
lateinit var fragmentView : View
lateinit var eventPosterImageView : ImageView
lateinit var eventBlurredPosterImageView: ImageView
lateinit var eventTitleTextView : TextView
lateinit var attendanceButton: Button
lateinit var dateTextView: TextView
lateinit var timeTextView : TextView
lateinit var venueTextView: TextView
lateinit var addressTextView: TextView
lateinit var speakerTextView: TextView
lateinit var priceTextView: TextView
lateinit var descriptionSnippetTextView: TextView
lateinit var readMoreTextViewButton : TextView
lateinit var mapMoreTextViewButton : TextView
lateinit var organizerTagTextView: TextView
lateinit var organizerLabelTextView: TextView
lateinit var mapFragment : SupportMapFragment
lateinit var googleMap: GoogleMap
lateinit var mContext : Context
lateinit var mActivity : FragmentActivity
lateinit var selectedEvent : Event
override fun onAttach(context: Context) {
super.onAttach(context)
mContext = context
activity?.let { mActivity = it }
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
fragmentView = inflater.inflate(R.layout.fragment_event_detail, container, false)
// setUpViewsDeclaration()
// setUpSafeArg()
// setUpListeners()
// updateUI()
return fragmentView
}
private fun setUpViewsDeclaration() {
titleTextView = mActivity.findViewById(R.id.destination_label_text_view)
eventPosterImageView = fragmentView.findViewById(R.id.imageView_event_detail_poster)
eventBlurredPosterImageView = fragmentView.findViewById(R.id.imageView_event_detail_blurred_poster)
eventTitleTextView = fragmentView.findViewById(R.id.textView_event_detail_event_title)
attendanceButton = fragmentView.findViewById(R.id.button_search_event_search)
dateTextView = fragmentView.findViewById(R.id.textView_event_detail_date_label)
timeTextView = fragmentView.findViewById(R.id.textView_event_detail_time_label)
venueTextView = fragmentView.findViewById(R.id.textView_event_detail_venue_label)
addressTextView = fragmentView.findViewById(R.id.textView_event_detail_address_label)
speakerTextView = fragmentView.findViewById(R.id.textView_event_detail_speaker_label)
priceTextView = fragmentView.findViewById(R.id.textView_event_detail_price_label)
descriptionSnippetTextView = fragmentView.findViewById(R.id.textView_event_detail_description_snippet_label)
readMoreTextViewButton = fragmentView.findViewById(R.id.textView_button_read_more)
organizerTagTextView = fragmentView.findViewById(R.id.textView_event_detail_organizer_tag)
organizerLabelTextView = fragmentView.findViewById(R.id.textView_event_detail_organizer_label)
mapMoreTextViewButton = fragmentView.findViewById(R.id.textView_button_map_more)
}
private fun setUpSafeArg() {
arguments?.let {
val args = EventDetailFragmentArgs.fromBundle(it)
selectedEvent = args.selectedEvent
}
}
private fun setUpListeners() {
eventPosterImageView.setOnClickListener {
val photoViewNavigation = EventDetailFragmentDirections.actionGlobalPhotoViewFragment(selectedEvent.posterDownloadPath)
Navigation.findNavController(fragmentView).navigate(photoViewNavigation)
}
eventBlurredPosterImageView.setOnClickListener {
val photoViewNavigation = EventDetailFragmentDirections.actionGlobalPhotoViewFragment(selectedEvent.posterDownloadPath)
Navigation.findNavController(fragmentView).navigate(photoViewNavigation)
}
readMoreTextViewButton.setOnClickListener {
val nextDestination = EventDetailFragmentDirections.actionToDescriptionDetail(selectedEvent.description)
Navigation.findNavController(fragmentView).navigate(nextDestination)
}
mapMoreTextViewButton.setOnClickListener {
val latitudeFloat = selectedEvent.coordinate.latitude.toFloat()
val longitudeFloat = selectedEvent.coordinate.longitude.toFloat()
val mapDetailDestination = EventDetailFragmentDirections.actionToMapDetailLocation(latitudeFloat,longitudeFloat)
Navigation.findNavController(fragmentView).navigate(mapDetailDestination)
}
}
private fun updateUI() {
Picasso.get()
.load(selectedEvent.posterDownloadPath)
.into(eventPosterImageView)
Picasso.get()
.load(selectedEvent.posterDownloadPath)
.transform(BlurTransformation(mContext,25,3))
.into(eventBlurredPosterImageView)
eventTitleTextView.text = selectedEvent.title
val dateStartingDate = DateTimeService.changeDateToString("EEEE, d MMMM yyyy",selectedEvent.dateTimeStart)
val timeStartingDate = DateTimeService.changeDateToString("HH:mm",selectedEvent.dateTimeStart)
val dateEndingDate = DateTimeService.changeDateToString("EEEE, d MMMM yyyy",selectedEvent.dateTimeFinish)
val timeEndingDate = DateTimeService.changeDateToString("HH:mm zzz",selectedEvent.dateTimeFinish)
dateTextView.text = dateStartingDate
timeTextView.text = "$timeStartingDate - $timeEndingDate"
venueTextView.text = selectedEvent.venue
addressTextView.text = selectedEvent.address
speakerTextView.text = "Penceramah: ${selectedEvent.speaker}"
organizerLabelTextView.text = selectedEvent.creatorFullName
descriptionSnippetTextView.text = selectedEvent.description
setUpGoogleMap()
}
private fun setUpGoogleMap() {
mapFragment = childFragmentManager.findFragmentById(R.id.map_event_detail) as SupportMapFragment
mapFragment.getMapAsync {
googleMap = it
val eventLocation = LatLng(selectedEvent.coordinate.latitude,selectedEvent.coordinate.longitude)
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(eventLocation,16f))
googleMap.addMarker(MarkerOptions().position(eventLocation).title("Lokasi Acara")).showInfoWindow()
googleMap.setOnMapClickListener {
val latitudeFloat = selectedEvent.coordinate.latitude.toFloat()
val longitudeFloat = selectedEvent.coordinate.longitude.toFloat()
val mapDetailDestination = EventDetailFragmentDirections.actionToMapDetailLocation(latitudeFloat,longitudeFloat)
Navigation.findNavController(fragmentView).navigate(mapDetailDestination)
}
}
}
}