TextView文字太多导致聊天气泡显示不完全
由于我的view是单独在一行展示,所以只能进行左or右约束,我进行右边约束之后给了margin_right导致view溢出显示区域(ConstraintLayout有一个20dp的paddingLeft),问题图片如下所示:
箭头指向的地方就是溢出被裁掉的部分
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp"
android:background="@mipmap/im_chat_bg_right"
android:gravity="center_vertical"
android:includeFontPadding="false"
android:lineSpacingMultiplier="1.1"
android:paddingLeft="15dp"
android:paddingTop="10dp"
android:paddingRight="18dp"
android:paddingBottom="10dp"
android:text="22111111111111111111111111111111111111111111111"
android:textColor="@color/white"
android:textSize="14sp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/msg_title_area"/>
解决方法:
1.如果这一行有两个及两个以上的view参考https://blog.youkuaiyun.com/qq_23089525/article/details/92591606?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_title-0&spm=1001.2101.3001.4242
2.尝试了很多方法,最终在外面包了一层LinearLayout解决问题,代码如下。
猜测是因为ConstraintLayout的padding没有对view生效

<LinearLayout
android:id="@+id/text_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/msg_title_area"
android:orientation="horizontal">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="15dp"
android:background="@mipmap/im_chat_bg_right"
android:gravity="center_vertical"
android:includeFontPadding="false"
android:lineSpacingMultiplier="1.1"
android:paddingLeft="15dp"
android:paddingTop="10dp"
android:paddingRight="18dp"
android:paddingBottom="10dp"
android:text="221111111111111111111111111111111111111111111111"
android:textColor="@color/white"
android:textSize="14sp" />
</LinearLayout>