فيديو المحاضرة
فيديو المحاضرة
بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.
رسوم متحركة
أمثلة كود
أمثلة قصيرة وبسيطة
كل مثال وراه زرار «شغّل خطوة بخطوة»: بيعلّم على السطر اللي بيتنفّذ ويطبع الناتج زي ما بيتنفّذ بالظبط. ده شرح تنفيذ الكود سطر بسطر، مش مترجم حقيقي جوه الصفحة.
المثال ١: توسيط بزر بقيدين
<Button android:id="@+id/buttonSave" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Save" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" />
المثال ٢: عرض 0dp ياخد المساحة
<TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="A long title that wraps" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" />
المثال ٣: بطاقة منتج
<androidx.cardview.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" app:cardCornerRadius="12dp" app:cardElevation="4dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="16dp"> <TextView android:text="Notebook" android:textSize="18sp" /> <TextView android:text="25 EGP" /> <Button android:text="Add" android:minHeight="48dp" /> </LinearLayout></androidx.cardview.widget.CardView>
اختبار قصير
اختبر فهمك
1. How many constraints does a view need at least?
2. layout_width="0dp" inside ConstraintLayout means:
3. A CardView holds:
4. The recommended spacing grid in Material Design is:
5. The smallest comfortable touch target is about:
تمارين
جرّب بإيدك
التمرين 1
وسّط TextView أفقياً ورأسياً بقيدين لكل اتجاه.
Centre a TextView horizontally and vertically with two constraints per axis.
Starter code:
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Centred" /><!-- TODO: add the four constraints -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Centred"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
Expected output
system: the text sits in the middle of the screen
التمرين 2
حط بطاقة فيها عنوان وسعر وزرار، وخلي الزرار 48dp على الأقل.
Build a card with a title, a price and a button, with the button at least 48dp tall.
Starter code:
<androidx.cardview.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content"> <!-- TODO: title, price, button --></androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="12dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView android:text="Notebook" />
<TextView android:text="25 EGP" />
<Button android:text="Add" android:minHeight="48dp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
Expected output
system: one card with three children, button 48dp
مشروع صغير في آخر المحاضرة
بطاقة درس في المقرر
الداتا: lesson-card: our own card with a lesson title, a duration and a button.
License / source: Our own layout; CardView reference by Google (link only). Reference page
الخطوات
- اعمل CardView بعرض الشاشة وارتفاع حسب المحتوى، وزوايا 12dp وظل 4dp.
- جواها LinearLayout رأسي بحشو 16dp.
- حط عنوان الدرس ومدته وزرار بمساحة 48dp على الأقل.
- اطبع سطر في الـ Log يقول إن البطاقة اتحمّلت.
Starter code:
setContentView(R.layout.activity_main);TextView title = findViewById(R.id.textTitle);Button open = findViewById(R.id.buttonOpen);// TODO: set the title text// TODO: log that the card is ready
setContentView(R.layout.activity_main);
TextView title = findViewById(R.id.textTitle);
Button open = findViewById(R.id.buttonOpen);
title.setText("Lesson 1: layouts");
Log.d("LessonCard", "card ready, button height " + open.getMinHeight());
Expected output
D/LessonCard: card ready, button height 48
مشروع نهاية الفصل
ملف المشروع العملي للفصل 4
ملف PDF فيه مشروع صغير بأسئلة عملية تطبّق بيها كل اللي اتعلمته في الفصل، مع حل نموذجي في الآخر.
Credits: the topic order follows the course notes "Mobile Application Development 1" by Dr. Muhammad Kashif Saeed (Applied College, Muhayil, King Khalid University), shared by the course owner. The explanations, diagrams, data and code in this lecture are our own; we copy nothing from the notes. Extra reference: Android developer documentation: layout types, ConstraintLayout, CardView, and Material Design (developer.android.com, m3.material.io).