Как сделать «активный пользовательский» макет, такой как Facebook / Messenger - PullRequest
1 голос
/ 28 марта 2020

Итак, вот мой XML файл для моего пользовательского макета

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="15dp"
        android:orientation="horizontal">
        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/users_profile_image"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:src="@drawable/profile_image"
            app:civ_border_color="#696969"
            app:civ_border_width="1dp"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_gravity="center"
            android:layout_marginLeft="5dp">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="20dp"
                android:id="@+id/username_layout"
                android:padding="5dp"
                android:text="username"
                android:textColor="#353758"
                android:textStyle="bold"
                />
            <ImageView
                android:id="@+id/user_item_online"
                android:layout_width="12dp"
                android:layout_height="12dp"
                android:layout_gravity="center_vertical"
                android:src="@drawable/user_state"
                android:visibility="visible"
                />
        </LinearLayout>
    </LinearLayout>
</RelativeLayout>

, и вот как это выглядит: user_layout

но я хочу это так же, как Facebook или мессенджер, я имею в виду, когда пользователь онлайн, точка прикреплена к его фотографии профиля.

Ответы [ 2 ]

1 голос
/ 28 марта 2020

Я предложу снять unsing ConstraintLayout для этого. Это легче! Для ConstraintLayout вам нужно добавить эту зависимость в ваш build.gradle файл приложения:

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

Тогда вы можете сделать это следующим образом:

<?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="wrap_content"
    android:padding="15dp"
    android:orientation="vertical">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/users_profile_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:src="@drawable/profile_image"
        app:civ_border_width="1dp"
        app:civ_border_color="#696969"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"/>

    <TextView
        android:id="@+id/username_layout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:text="username"
        android:textColor="#353758"
        android:textSize="20dp"
        android:textStyle="bold"
        android:layout_marginStart="5dp"
        android:layout_marginLeft="5dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toEndOf="@id/users_profile_image"
        app:layout_constraintEnd_toEndOf="parent"/>

    <ImageView
        android:id="@+id/user_item_online"
        android:layout_width="12dp"
        android:layout_height="12dp"
        android:src="@drawable/user_state"
        android:visibility="visible"
        android:translationX="-14dp"
        android:translationY="-14dp"
        app:layout_constraintEnd_toEndOf="@id/users_profile_image"
        app:layout_constraintBottom_toBottomOf="@id/users_profile_image"
        app:layout_constraintStart_toEndOf="@id/users_profile_image"
        app:layout_constraintTop_toBottomOf="@id/users_profile_image"/>
</androidx.constraintlayout.widget.ConstraintLayout>
0 голосов
/ 28 марта 2020
  1. Создание родительского макета (LinearLayout)
  2. Создание дочернего макета для изображения профиля (RelativeLayout)
  3. Добавьте значок онлайн к макету изображения профиля и добавьте 'android: layout_alignParentBottom = "true" 'и' android: layout_alignParentRight = "true" '
  4. Добавить текстовое представление (для имени) в родительский макет.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...