شرح ScrollView في الاندرويد android studio و اضافة عدة مشاهد اليها
03 March
في الاندرويد هذا المشهد ( ScrollView ) غالبا ما يستعمل مع النصوص او النوافد التي تحتوي على عدة مشاهد حيث تكون النافدة غير كافية هنا ياتي دور هذا المشهد حيث يمكنك الاستعانة به للحصول على نافدة قابلة لزايدة الطول مع شرح كيفية اضافة عدة مشاهد اليها android studio.
و كمثال لدي نص طويل كما في الصورة.
هذا قبل و بعد اضافة المشهد
اولا انشئ نافدة جديدة أسميها ScrollLayout
المشكلة التي قد تواجهها هي انه لا تقبل اكثر من مشهد دخلها
و الحل و هو ان تضع نمودج(Linear Layout) دخلها تم تضع المشاهد داخل النمودج وهذا مثال على ذلك
اقوم بسحب ScrollView الى النافدة و أضع (Linear Layout) ثم اضيف بعض المشاهد حتى يتوضح الامر كما العادة او نسخ هذا الكود
المشكلة التي قد تواجهها هي انه لا تقبل اكثر من مشهد دخلها
و الحل و هو ان تضع نمودج(Linear Layout) دخلها تم تضع المشاهد داخل النمودج وهذا مثال على ذلك
اقوم بسحب ScrollView الى النافدة و أضع (Linear Layout) ثم اضيف بعض المشاهد حتى يتوضح الامر كما العادة او نسخ هذا الكود
<relativelayout android:layout_height="match_parent" android:layout_width="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context="com.learnmore.androidbella.ScrollLayout" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <scrollview android:id="@+id/scrollView" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:layout_alignparenttop="true" android:layout_height="wrap_content" android:layout_width="wrap_content"> <linearlayout android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical"> <button android:id="@+id/button2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="New Button"/> <button android:id="@+id/button3" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="New Button"/> <button android:id="@+id/button4" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="New Button"/> <button android:id="@+id/button5" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="New Button"/> <button android:id="@+id/button6" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="New Button"/> <button android:id="@+id/button7" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="New Button"/> <button android:id="@+id/button8" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="New Button"/> <button android:id="@+id/button9" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="New Button"/> <button android:id="@+id/button10" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="New Button"/> <button android:id="@+id/button11" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="New Button"/> <button android:id="@+id/button12" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="New Button"/> </linearlayout> </scrollview> </relativelayout>
سالاحظ انني ارى استطيع رؤية كل الازرار حتى لو كان الشاشة صغيرة
اترك لنا تعليقا