Android线性布局宽度

Android线性布局宽度,android,css,android-layout,Android,Css,Android Layout,我有speechbubbles,里面有两个文本视图。第一个文本视图是消息,第二个是发送消息的时间 第二个文本视图的布局宽度基于消息的宽度,用于将时间向左或向右对齐。如果短消息用户看不到时间完成 这是正确的(如果消息不短): 如果要将消息缩短,请执行以下操作: Hello! 00:00 Hel 00 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.andr

我有speechbubbles,里面有两个文本视图。第一个文本视图是消息,第二个是发送消息的时间

第二个文本视图的布局宽度基于消息的宽度,用于将时间向左或向右对齐。如果短消息用户看不到时间完成

这是正确的(如果消息不短):

如果要将消息缩短,请执行以下操作:

Hello!
 00:00
Hel
 00

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/gravity"
    android:gravity="right"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:id="@+id/container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="5dip"
        android:paddingTop="8dp"
        android:paddingBottom="11dp"
        android:paddingLeft="9dp"
        android:background="@drawable/speechbubble" >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="match_parent" >

            <TextView
                android:id="@+id/message"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/singleMessageTime"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/message" />
        </LinearLayout>

    </LinearLayout>

</LinearLayout>
Hel
00

怎么了?

我不确定为什么需要3个嵌套的线性布局,我认为这应该可以完成您正在尝试的工作

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/gravity"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:gravity="end"
     android:orientation="vertical"
     android:layout_margin="5dip"
     android:paddingTop="8dp"
     android:paddingBottom="11dp"
     android:paddingLeft="9dp"
     android:background="@drawable/speechbubble">

     <TextView
         android:id="@+id/message"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Hello!" />

     <TextView
         android:id="@+id/singleMessageTime"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="00:00" />
</LinearLayout>

只需将minwidth或minEMS设置为控制整个版面大小的textview

android:minWidth=“40dp”
你有图像可以更好地看到你需要的东西吗?当然,我有左右的演讲泡泡。文本与speechbubble向左或向右对齐。如果我使用您的代码,则只剩下文本视图和speechbubble。您是否以编程方式更改重力布局?您可以将speechbubble drawable添加到重力布局中。更改此布局的重力应将对齐方式从左到右更改。如果宽度小于40,我是否可以检查消息文本的宽度,并将布局宽度从wrap_content example更改为40?我希望你能理解我糟糕的英语。你可以通过使用:layout.setLayoutParams(newlinearlayout.LayoutParams(newWidth,layout.getHeight())更改版面宽度;