2017-02-12 8 views
0

У меня есть этот xml-макет для Android, который выглядит так, и, как вы видите, у него есть чаты. Я хотел преобразовать его с LinearLayout в ConstraintLayout
.
Это LinearLayout версия, и это выглядит нормальноКак создать чат-создание пузырей в ConstraintLayout

enter image description here

Это ConstraintLayout версия и чат Bubbels выглядят не так красиво.

enter image description here

Я хочу некоторую помощь с этим пузыри. Стрелка, как вы видите, трудно сдержать, чтобы она выглядела хорошо. Я добавил один android.support.constraint.Guideline, чтобы сделать некоторые ограничения, но не работает.

Вот ConstraintLayout XML

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="end|center_vertical"> 

    <com.github.curioustechizen.ago.RelativeTimeTextView 
     android:id="@+id/timestamp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="?AppTheme.ChatBubbleTextColor" 
     android:textSize="@dimen/chat_timestamp_text_size" 
     tools:text="Just Now" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintVertical_bias="1.0" 
     app:layout_constraintRight_toLeftOf="@+id/message" 
     android:layout_marginEnd="8dp" 
     android:layout_marginRight="8dp" /> 

    <TextView 
     android:id="@+id/message" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/bg_balloon" 
     android:padding="8dp" 
     android:textColor="?AppTheme.ChatBubbleTextColor" 
     android:textSize="@dimen/chat_message_body_text_size" 
     tools:text="This is chat message" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/guideline1" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginTop="8dp" 
     android:layout_marginBottom="8dp" /> 

    <android.support.constraint.Guideline 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/guideline1" 
     android:orientation="vertical" 
     tools:layout_editor_absoluteY="0dp" 
     tools:layout_editor_absoluteX="218dp" 
     app:layout_constraintGuide_percent="0.859375" /> 

    <View 
     android:layout_width="8dp" 
     android:layout_height="8dp" 
     android:background="?AppTheme.ChatBubbleBackGroundColor" 
     android:rotation="45" 
     android:id="@+id/view" 
     app:layout_constraintRight_toLeftOf="@+id/thumbnail" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="@+id/guideline1" 
     app:layout_constraintHorizontal_bias="0.0" 
     android:layout_marginEnd="16dp" 
     android:layout_marginRight="16dp" /> 

    <ImageView 
     android:id="@+id/thumbnail" 
     android:layout_width="22dp" 
     android:layout_height="24dp" 
     tools:src="@drawable/tw__composer_logo_blue" 
     app:layout_constraintTop_toTopOf="parent" 
     app:layout_constraintBottom_toBottomOf="parent" 
     android:layout_marginEnd="8dp" 
     app:layout_constraintRight_toRightOf="parent" 
     android:layout_marginRight="8dp" /> 

</android.support.constraint.ConstraintLayout> 

Может быть, есть какая-то библиотека на GitHub, что создает пузыри или какие-либо идеи по этому поводу было бы здорово?

ответ

0

Я думаю, что я решил это так, благодаря ChatMessageView

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dp" 
    android:layout_marginBottom="20dp"> 

    <com.github.curioustechizen.ago.RelativeTimeTextView 
     android:id="@+id/timestamp" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginStart="16dp" 
     android:textColor="?AppTheme.ChatBubbleTextColor" 
     android:textSize="@dimen/chat_timestamp_text_size" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintHorizontal_bias="1.0" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/guideline1" 
     tools:text="Just Now" 
     app:layout_constraintTop_toBottomOf="@+id/chatMessageView" 
     android:layout_marginTop="3dp" /> 

    <android.support.constraint.Guideline 
     android:id="@+id/guideline1" 
     android:layout_width="0dp" 
     android:layout_height="110dp" 
     android:orientation="vertical" 
     app:layout_constraintGuide_percent="0.88611114" 
     tools:layout_editor_absoluteX="319dp" 
     tools:layout_editor_absoluteY="0dp" /> 

    <ImageView 
     android:id="@+id/thumbnail" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:layout_marginTop="16dp" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="@+id/guideline1" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toTopOf="parent" 
     tools:src="@drawable/tw__composer_logo_blue" /> 

    <me.himanshusoni.chatmessageview.ChatMessageView 
     android:id="@+id/chatMessageView" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginStart="8dp" 
     android:layout_marginTop="16dp" 
     app:cmv_arrowGravity="center" 
     app:cmv_arrowPosition="right" 
     app:cmv_backgroundColor="?AppTheme.ChatBubbleBackGroundColor" 
     app:cmv_backgroundColorPressed="?AppTheme.ChatBubbleBackGroundColorPressed" 
     app:cmv_contentPadding="10dp" 
     app:cmv_cornerRadius="10dp" 
     app:cmv_showArrow="true" 
     app:layout_constraintBottom_toBottomOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toLeftOf="@+id/guideline1" 
     app:layout_constraintTop_toTopOf="parent"> 

     <ImageView 
      android:id="@+id/image" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="?AppTheme.ChatBubbleBackGroundColor"/> 

    </me.himanshusoni.chatmessageview.ChatMessageView> 

</android.support.constraint.ConstraintLayout> 
Смежные вопросы