Free tutorials & notes in Hindi & English · Clean code examples 🧰 मुफ़्त PDF और फ़ोटो टूल्स →
🎨 UI – Views और Layouts  ·  Lesson 16

ScrollView, CardView और Material Components

ScrollView और NestedScrollView

जब content screen से लंबा हो, उसे scroll container में रखें। NestedScrollView (AndroidX) use करें — यह collapse होने वाले toolbars और CoordinatorLayout के साथ अच्छा चलता है।

XML
<androidx.core.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <!-- exactly ONE child -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="16dp">

        <!-- many views here: text, images, cards, buttons … -->
    </LinearLayout>
</androidx.core.widget.NestedScrollView>
NestedScrollViewvertical scrollLinearLayout (एकमात्र child)सब कुछ रखता हैTextViews, ImageViews, Cards, Buttonsआपका content
One child rule

HorizontalScrollView

XML – scroll होने वाले chips
<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="none">

    <com.google.android.material.chip.ChipGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:singleLine="true">
        <!-- chips … -->
    </com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>

MaterialCardView

XML – course card
<com.google.android.material.card.MaterialCardView
    android:id="@+id/cardCourse"
    style="@style/Widget.Material3.CardView.Elevated"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="12dp"
    android:clickable="true"
    android:focusable="true"
    app:cardCornerRadius="16dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="160dp"
            android:contentDescription="@null"
            android:scaleType="centerCrop"
            android:src="@drawable/course_android" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:text="Android with Kotlin"
            android:textAppearance="?attr/textAppearanceTitleLarge" />
    </LinearLayout>
</com.google.android.material.card.MaterialCardView>
StyleLook
Widget.Material3.CardView.ElevatedShadow
Widget.Material3.CardView.FilledTinted background, shadow नहीं
Widget.Material3.CardView.OutlinedBorder

Material buttons

XML – button styles
<!-- filled (main action) -->
<com.google.android.material.button.MaterialButton
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="Enroll now" app:icon="@drawable/ic_add" />

<!-- tonal (secondary) -->
<com.google.android.material.button.MaterialButton
    style="@style/Widget.Material3.Button.TonalButton"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="Add to wishlist" />

<!-- outlined -->
<com.google.android.material.button.MaterialButton
    style="@style/Widget.Material3.Button.OutlinedButton"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="Syllabus" />

<!-- text button (least important) -->
<com.google.android.material.button.MaterialButton
    style="@style/Widget.Material3.Button.TextButton"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="Share" />
9:41▮▮ 85%Buttons⋮+ ENROLL NOWAdd to wishlistSyllabusShare
Filled → tonal → outlined → text (importance ज़्यादा से कम)

Floating Action Button

XML + Kotlin
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
    android:id="@+id/fabEnroll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="16dp"
    android:text="Enroll"
    app:icon="@drawable/ic_add" />

// Kotlin – shrink to a round FAB when the user scrolls down
binding.scroll.setOnScrollChangeListener { _, _, y, _, oldY ->
    if (y > oldY) binding.fabEnroll.shrink() else binding.fabEnroll.extend()
}

Progress indicators

XML + Kotlin
<!-- spinner while loading -->
<com.google.android.material.progressindicator.CircularProgressIndicator
    android:id="@+id/loader"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:indeterminate="true" />

<!-- course progress bar -->
<com.google.android.material.progressindicator.LinearProgressIndicator
    android:id="@+id/progressCourse"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:trackCornerRadius="6dp"
    app:trackThickness="10dp" />

// Kotlin
binding.progressCourse.setProgressCompat(65, true)   // animate to 65%
binding.loader.isVisible = false

Example: course detail screen

9:41▮▮ 85%←Android Course⋮🖼️course bannerAndroid with Kotlin10 weeks · ₹5,999 · ⭐ 4.8Week 1: Kotlin basics5 lessonsWeek 2: Layouts & vi…6 lessons+ Enroll9:41▮▮ 85%←Android Course⋮Week 3: RecyclerView4 lessonsWeek 4: Navigation5 lessonsYour progress 65%Fee₹5,999ENROLL NOW
Banner, cards, progress और buttons वाला NestedScrollView — ऊपर और नीचे scroll करके

आम गलतियाँ

  • ScrollView में दो children → crash "ScrollView can host only one direct child"।
  • ScrollView के अंदर child height match_parent → wrap_content use करें (और छोटे content के लिए fillViewport)।
  • पुराने android.widget.Button styles को Material styles के साथ मिलाना → अलग-अलग look; हर जगह MaterialButton use करें (theme <Button> के लिए यह अपने आप करती है)।

सारांश

  • लंबी screens के लिए ठीक एक child वाला NestedScrollView।
  • Grouped content के लिए MaterialCardView; Material button styles importance दिखाते हैं।
  • Main action के लिए FAB; loading और progress के लिए Circular/Linear progress indicators।
✅ Practice

ऊपर वाली course detail screen बनाइए: banner, title, 5 week cards, 40% पर progress bar और scroll down पर shrink होने वाला extended FAB।

अक्सर पूछे जाने वाले प्रश्न (FAQ)

ScrollView में सिर्फ़ एक child क्यों?
ScrollView एक content view को scroll करता है। उसके अंदर LinearLayout या ConstraintLayout रखें और सारे views उसी में डालें।
क्या RecyclerView को ScrollView में रखें?
बचें — RecyclerView recycling खो देता है और धीमा हो जाता है। अलग view types वाला एक RecyclerView या ConcatAdapter use करें।
CardView या MaterialCardView?
Material library का MaterialCardView use करें। यह Material 3 styles, strokes, checkable cards और theme colours support करता है।
← Android Tutorial (Kotlin)
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

अगला topicToast, Snackbar और Dialogs आपकी प्रगति: 16 / 43 (37%) · Lesson 17 / 43 आगे बढ़ें →

यह lesson कैसा लगा?

आपकी राय से हम content और बेहतर बनाते हैं।

अपना review और सुझाव लिखें (वैकल्पिक)

Review approve होने के बाद आपका नाम और शहर इसके साथ public दिख सकते हैं। Email या phone न लिखें।

▶ CodingEasily on YouTube

Video से सीखें – आसान Hindi में

चुनी हुई video: RDBMS भाग 3 – Class XI Commerce IT

▶ Channel subscribe करें