JavaRush /Курсы /Курс "Программирование под Андроид" /Равномерно распределяем дочерние View-элементы

Равномерно распределяем дочерние View-элементы

Курс "Программирование под Андроид"
2 уровень , 4 лекция
Открыта

Атрибут weight (вес) в линейном макете.

По этой ссылке можно поэкспериментировать с XML.

Подробнее о линейном макете на Stack Overflow: равномерное распределение дочерних элементов.

Свои ответы и вопросы можете оставлять в комментариях.

Комментарии (70)
ЧТОБЫ ПОСМОТРЕТЬ ВСЕ КОММЕНТАРИИ ИЛИ ОСТАВИТЬ КОММЕНТАРИЙ,
ПЕРЕЙДИТЕ В ПОЛНУЮ ВЕРСИЮ
Khalim Rustamov Уровень 2
11 декабря 2023
Не открывается XML
Gruster Уровень 35
29 ноября 2021
layout_weight позволяет задать вес макета, аналог процентов в Html если задать layout_width="0dp" - то мы отменяем действие равняться по ширине контента
Алексей Опарин Уровень 27
29 сентября 2021
Аналог свойства flex-grow для html разметки
Саша Бульба Уровень 10
17 июля 2021
Мы имеем вертикальный макет, поэтому присваеваем во всех view для android:layout_height значение в ноль dp, а затем присвоить для android:layout_weight значение 1 для равномерного распределения.
setverg Уровень 1
28 июня 2021
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="Tom" android:layout_height="0dp" android:layout_weight="1" android:layout_width="wrap_content" android:textSize="24sp" /> <TextView android:text="Tim" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:textSize="24sp" /> <TextView android:text="Todd" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:textSize="24sp" /> </LinearLayout>
Alex Snt. Уровень 1
7 июня 2021
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/darker_gray" android:paddingLeft="16dp" android:paddingRight="16dp"> <TextView android:text="Tom" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="24sp" android:layout_weight="1" /> <TextView android:text="Tim" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="24sp" android:layout_weight="1"/> <TextView android:text="Todd" android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="24sp" android:layout_weight="1"/> </LinearLayout>
Samurai Уровень 10
30 марта 2021

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/darker_gray"
    android:paddingLeft="16dp"
    android:paddingRight="16dp">

    <TextView
        android:text="VIP List"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#000080"
		android:layout_weight="1"
        android:textSize="24sp" />

    <TextView
        android:text="Kunal"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#008080"
        android:layout_weight="1"
        android:textSize="24sp" />

    <TextView
        android:text="Kagure"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top"
        android:background="#00FF7F"
        android:textSize="24sp" />

    <TextView
        android:text="Lyla"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#9ACD32"
        android:layout_weight="1"
        android:textSize="24sp" />

</LinearLayout>
30 марта 2021
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:text="Tom" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:textSize="24sp" /> <TextView android:text="Tim" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:textSize="24sp" /> <TextView android:text="Todd" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:textSize="24sp" /> </LinearLayout>
28 февраля 2021
ну как я понял из статьи, что данная конструкция позволяет равномерно распологать текст по любой площади не зависимо от диаметра экрана
Tywin Lannister Уровень 7
4 декабря 2023
ага, особенно если экран у вас круглый)))
Руслан Асаев Уровень 14
19 января 2021
<TextView android:text="Todd" android:textStyle="bold|italic" android:textColor="#FF4081" android:gravity="center" android:layout_width="wrap_content" android:layout_height="0dp" android:layout_weight="1" android:layout_margin="5dp" android:textSize="24sp" /> </LinearLayout>