آموزش ScrollView به زبان کوتلین در اندروید

سلام دوستان و توسعه دهندگان عزیز در این سری از آموزش برنامه نویسی اندروید به آموزش ScrollView به زبان کوتلین در اندروید می پردازیم از ScrollView به منظور ساخت یک لایه قابل scroll استفاده می شود در ادامه با ما همراه باشید تا نخوه استفاده از Scrollview را در کوتلین یاد گیرید .
 
ابتدا یکسری از attribute های Scrollview را مورد بررسی قرار میدهیم.
android:fillViewport : به منظور کشیده شدن scrollview استفاده می شود (مقدار true این کار را انجام میدهد).
android:layoutAnimation : به منظور اضافه کردن انیمیشن سفارشی استفاده می شود.
android:id : یک آیدی منحصر به فرد برای آن در نظر می گیرید.
 
وارد strings.xml شده در مسیر res/values قرار دارد و کدهای زیر را در آن جایگزین کنید.

<resources>
    <string name="app_name">ScrollView - Programchi</string>
    <string name="no_image">No Image</string>
</resources>

در ادامه یکسری عکس برای شما قرار میدهیم آنها را دانلود و در پوشه drawable قرار دهید.
لینک دانلود
وارد یک layout شده در زیر ما وارد activity_main.xml شدیم و سپس کدهای زیر را در آن قرار دهید.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <ImageView
            android:id="@+id/image1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/guava"/>
        <ImageView
            android:id="@+id/image2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/jackfruit"/>
        <ImageView
            android:id="@+id/image3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/mix_fruit"/>
        <ImageView
            android:id="@+id/image4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/pomegranate"/>
        <ImageView
            android:id="@+id/image5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/strawberry"/>
        <ImageView
            android:id="@+id/image6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/zespri_kiwi"/>
    </LinearLayout>
</ScrollView>

در بلالا یکسری Image درون ScrollView قرار دادیم ولی دقت کنید باید درون ScrollView همیشه یک  child وجود داشته باشد سپس درون آن child یکسری view قرار دهید.
در کل باید مثل زیر عمل کنید برای ساخت ScrollView

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    </LinearLayout>
</ScrollView>

و  در بخش MainActivity.kt همانند زیر خواهد بود.

package com.tutorialwing.scrollview
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

در بالا کد خاصی اضافه نشده است/
 
این آموزش هم به پایان رسید.
موفق باشید.

مطالعه بیشتر