Emulyatorni sozlang, yangi loyiha yarating
Download 92.99 Kb. Pdf ko'rish
|
620-20 K.Temirov compressed
break
; case "Image 4" : 38 image.setImageResource(R.drawable.image4); break ; } Endi har qanday rasmni drawable papkasiga joylashtirish qoladi. Tasvirlar image1 deb nomlanishi kerak.jpeg, image2.jpeg va boshqalar, yoki switch-case dizaynida siz chiziqdagi rasmlarga yo'lni o'zgartirishingiz kerak R.drawable.to'liq ism bilan matn maydoni haqida unutmang. Ishga tushirish ilova va siz rasm va matn bilan o'z ro'yxatingizni ko'rasiz. Misol 26-rasmda ko'rsatilgan. 26-rasm-5-sonli laboratoriya ishining namunasi 39 Endi yanada kuchli va zamonaviy elementni ko'rib chiqing RecyclerView 1 . Ushbu element faqat ro'yxat elementlarini yaratadi, ekranda foydalanuvchiga ko'rinadigan darajada, shuning uchun ro'yxat katta bo'lsa, u xotirani sezilarli darajada tejaydi – va ilovalarda ro'yxatlar odatda uzun bo'ladi. Foydalanuvchi ro'yxatni pastga aylantirganda, yuqori element ekrandan tashqariga chiqadi va ko'rinmas bo'lib qoladi, shu bilan birga uning tarkibi tozalanadi va ekranda keraksiz bo'lgan ushbu element ekranning pastki qismiga joylashtiriladi va quyidagi ro'yxat elementlarining yangi ma'lumotlari bilan to'ldiriladi, ya'ni .qayta ishlatilgan (qayta ishlangan). RecyclerView ishining umumiy modeli quyida keltirilgan. 26.2-rasm-RecyclerView ish modeli 2 1 https://metanit.com/java/android/5.11.php 2 http://developer.alexanderklimov.ru/android/views/recyclerview-kot.php 40 EmptyActivity bilan yangi loyiha yarating. Birinchi narsa – bu modul darajasidagi gradle fayliga quyidagi bog'liqlikni qo'shing: implementation 'androidx.recyclerview:recyclerview:1.2.1' Keyinchalik, ro'yxatning alohida elementi uchun tartibni tuzishingiz kerak, ammo u biz allaqachon ListView bilan loyihada turibmiz va list_item faylida yotamiz.xml: 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 ="match_parent" tools :context =".MainActivity" > < ImageView android :id ="@+id/imageView" android :layout_width ="wrap_content" android :layout_height ="wrap_content" android :layout_marginStart ="16dp" android :layout_marginLeft ="16dp" android :layout_marginTop ="16dp" app :layout_constraintStart_toStartOf ="parent" app :layout_constraintTop_toTopOf ="parent" app :srcCompat ="@mipmap/ic_launcher" /> < TextView android :id ="@+id/textView" android :layout_width ="wrap_content" android :layout_height ="wrap_content" android :layout_marginStart ="8dp" android :layout_marginLeft ="8dp" android :layout_marginEnd ="8dp" android :layout_marginRight ="8dp" android :text ="TextView" android :textSize ="24sp" app :layout_constraintBottom_toBottomOf ="@+id/imageView" app :layout_constraintEnd_toEndOf ="parent" app :layout_constraintHorizontal_bias ="0.077" app :layout_constraintStart_toEndOf ="@+id/imageView" app :layout_constraintTop_toTopOf ="@+id/imageView" /> androidx.constraintlayout.widget.ConstraintLayout > Shuningdek, bizga images fayli kerak bo'ladi.rasm nomlarini o'z ichiga olgan res/values papkasidagi xml va bu rasmlarning o'zi drawable papkasida. Endi TextView "Salom dunyo" ni o'chirib tashlang va RecyclerView komponentini qo'shing activity_main.xml. Biz ro'yxat elementining dizaynini ko'rish uchun 41 list_item-da yaratilgan.xml, @layout/list_item qiymatini mulkka qo'shing Listitem deb nomlangan RecyclerView. Bundan tashqari, siz quyidagilarni qo'shishingiz kerak RecyclerView tavsif kodidagi xususiyat: app :layoutManager ="androidx.recyclerview.widget.LinearLayoutManager" Bu RecyclerView ro'yxatni qanday ko'rsatishni bilishi uchun kerak. Biz avvalgi loyihamizni optimallashtiramiz: RecyclerView-ni buzadigan 2 ta qo'shimcha sinf yaratamiz . Biz birinchi sinfni Image deb ataymiz, unda ro'yxat elementining kerakli ma'lumotlarini aniqlashning asosiy usullari mavjud : public class Image { private String name ; Download 92.99 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling