Layouts and Views

Understanding Android UI components and layout management

Introduction to Layouts and Views

Layouts और Views Android app development में UI बनाने के basic building blocks हैं। Layouts views को organize करते हैं और Views actual UI elements होते हैं।

Layouts and Views are the basic building blocks for creating UI in Android app development. Layouts organize views, and Views are the actual UI elements.

Key Concepts (मुख्य अवधारणाएं):

  • Layouts views को arrange करने के लिए containers होते हैं
  • Layouts are containers for arranging views
  • Views actual UI elements होते हैं जैसे buttons, text fields, images
  • Views are actual UI elements like buttons, text fields, images
  • Layouts nested हो सकते हैं (एक layout दूसरे layout के अंदर)
  • Layouts can be nested (one layout inside another)
  • Views का size और position layout parameters से control होता है
  • View size and position are controlled by layout parameters

Common Layouts (सामान्य लेआउट्स)

Android में commonly used layouts:

Commonly used layouts in Android:

Layout (लेआउट) Description (विवरण)
LinearLayout Views को एक line में arrange करता है (horizontal या vertical)
LinearLayout Arranges views in a single line (horizontal or vertical)
RelativeLayout Views को एक-दूसरे के relative position करता है
RelativeLayout Positions views relative to each other
ConstraintLayout Views को constraints के based position करता है
ConstraintLayout Positions views based on constraints
FrameLayout Views को एक-दूसरे के top पर stack करता है
FrameLayout Stacks views on top of each other
GridLayout Views को grid pattern में arrange करता है
GridLayout Arranges views in a grid pattern

Common Views (सामान्य व्यूज़)

Android में commonly used views:

Commonly used views in Android:

  • TextView: Text display करने के लिए
  • TextView: For displaying text
  • EditText: User input लेने के लिए
  • EditText: For taking user input
  • Button: Click events handle करने के लिए
  • Button: For handling click events
  • ImageView: Images display करने के लिए
  • ImageView: For displaying images
  • RecyclerView: Lists और grids display करने के लिए
  • RecyclerView: For displaying lists and grids
  • Implementation Example (इम्प्लीमेंटेशन उदाहरण)

    Layout और Views को implement करने का example:

    Example of implementing layouts and views:

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <TextView
            android:id="@+id/titleText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello World!"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginTop="16dp"/>
    
        <Button
            android:id="@+id/actionButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Click Me"
            app:layout_constraintTop_toBottomOf="@id/titleText"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginTop="16dp"/>
    
    </androidx.constraintlayout.widget.ConstraintLayout>

    Best Practices (सर्वोत्तम प्रथाएं)

    Layouts और Views के साथ काम करने के best practices:

    Best practices for working with layouts and views:

  • Layout Hierarchy: Layout hierarchy को shallow रखें
  • Layout Hierarchy: Keep layout hierarchy shallow
  • ConstraintLayout: Complex layouts के लिए ConstraintLayout का use करें
  • ConstraintLayout: Use ConstraintLayout for complex layouts
  • RecyclerView: Lists के लिए RecyclerView का use करें
  • RecyclerView: Use RecyclerView for lists
  • View Binding: View references के लिए View Binding का use करें
  • View Binding: Use View Binding for view references