آموزش NestedScrollView در کوتلین

سلام دوستان در این سری از آموزش برنامه نویسی اندروید به آموزش NestedScrollView در کوتلین می پردازیم قبلا آموزش NestedScrollView را در اندروید برای شما قرار دادیم در این آموزش NestedScrollView را زبان برنامه نویسی کوتلین (kotlin) قرار میدهیم از NestedScrollView به منظور استفاده از Scroll درون یک ScrollView دیگر می توان از NestedScrollView استفاده کرد با ما همراه باشید.
 
ابتدا وارد فایل strings.xml شده در مسیر res/values قرار دارد و کدهای زیر را در آن قرار دهید.

<resources>
	<string name="app_name">NestedScrollView</string>
	<string name="no_image">No Image</string>
	<string name="nested_scroll_text">orjinakteb.com presents tutorial on NestedScrollView!
		NestedScrollView is just like ScrollView, but it supports acting as both a nested
		scrolling parent and child on both new and old versions of Android. Nested scrolling
		is enabled by default. NestedScrollView is used when there is need for scrolling inside
		another scrolling view. Normally this would be difficult task because system would be
		unable to decide which view to scroll. This is where NestedScrollView comes into role.
	</string>
</resources>

در بالا یک رشته طولانی تعریف کردیم تا nestedscroll را به واضح نمایان کنیم.
در ادامه یکسری عکس برای شما قرار میدهیم آنها را دانلود و در پوشه 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:layout_marginBottom="20dp"
        android:gravity="center"
        android:orientation="vertical">
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_margin="20dp"
            android:background="@android:color/white"
            android:padding="10dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/nested_scroll_text"/>
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/guava"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/jackfruit"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/mix_fruit"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/pomegranate"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/strawberry"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:contentDescription="@string/no_image"
            android:src="@drawable/zespri_kiwi"/>
    </LinearLayout>
</ScrollView>

و در نهایت کد خاصی هم در MainActivity.kt قرار نخواهیم داد و همانند زیر خواهد بود.

package ir.programchi
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)
    }
}

 
این آموزش به پایان رسید.
موفق باشید.
 

مطالعه بیشتر