我正在尝试为Android应用程序制作聊天视图,但我有一个问题,聊天泡沫挤压消息时间,直到它完全折叠它,然后它包装到下一行。 这是xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left|center"
android:orientation="horizontal"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:gravity="left|center"
android:orientation="horizontal">
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/chat_levi"
android:padding="10dp"
android:text="Insert text here"
android:textColor="@color/blueGray50"
android:textSize="16sp" />
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="bottom|left"
android:text="18:30"
android:textSize="14sp" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.2" />
</LinearLayout>
我还在聊天中为其他用户设置了另一个布局,对他来说,我只是将所有重力左移改为权利,并交换了一些元素的位置,如上图所示(它的代码非常相似,所以我排除了它,但是如果有人要求它,我会添加它)。对于那个,我得到了预期的效果。
是否有某种方法可以让第一个与镜像方式相同?
答案 0 :(得分:0)
请尝试以下代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|center"
android:orientation="horizontal">
<FrameLayout
android:layout_weight="0.8"
android:layout_width="0dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/content"
android:layout_height="wrap_content"
android:background="@drawable/chat_levi"
android:padding="10dp"
android:layout_width="wrap_content"
android:text="Insert texaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaat here"
android:textColor="@color/blueGray50"
android:textSize="16sp" />
</FrameLayout>
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="bottom|left"
android:text="18:30"
android:textSize="14sp" />
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0.2" />
</LinearLayout>
</RelativeLayout>
upd:最后固定间距
答案 1 :(得分:0)
可能有一百万种方法可以对这只猫进行修饰,但是你已经使用权重进行线性布局,你可以为你的文本视图做一些非常相似的事情:
float
你可以使用权重来为你的时间戳提供更多或更少的空间。
EDIT ******
另一种为这只猫设置皮肤的方法就是将maxwidth放在你的xml
上 <TextView
android:id="@+id/content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:padding="10dp"
android:text="Insert ioadjfojdajidijfaseidfijoajsdifjasdijfijsadpfaosdjiofipasjdifapsjdfjasdjfasidjfasdjfoipjoijoij here"
android:textSize="16sp" />
<TextView
android:id="@+id/time"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="bottom|left"
android:text="18:30"
android:textSize="14sp" />
但是,您必须为不同的布局管理它。
答案 2 :(得分:0)