Когда использовать:
weight
) для пропорционального распределения пространства<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Button 2"/>
</LinearLayout>
Плюсы:
Минусы:
Когда использовать:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button1"
android:text="Button 2"/>
</RelativeLayout>
Плюсы:
Минусы:
Когда использовать:
<ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="Button 1"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@id/button1"
app:layout_constraintTop_toTopOf="@id/button1"
android:text="Button 2"/>
</ConstraintLayout>
Плюсы:
Минусы:
Когда использовать:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/background"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Overlay Text"/>
</FrameLayout>
Плюсы:
Минусы:
Когда использовать:
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="2">
<TextView
android:text="Name:"/>
<EditText
android:layout_columnWeight="1"/>
<TextView
android:text="Email:"/>
<EditText
android:layout_columnWeight="1"/>
</GridLayout>
Плюсы:
Минусы:
Когда использовать:
<CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<AppBarLayout>
<CollapsingToolbarLayout>
<!-- Content -->
</CollapsingToolbarLayout>
</AppBarLayout>
<RecyclerView
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</CoordinatorLayout>
Плюсы:
Минусы:
Современный подход: