我想布局应该包装其内容的视图,但它不应该比其父宽度少100多pd。我如何使用RelativeLayout或其他布局来做到这一点?我现在所拥有的东西总是会使视图100dp的数量少于它的父级,这样就有了另一个视图的空间。如何使用最大宽度的wrap_content?
这张照片是什么,我有一个例子:
正如你所看到的,文本不能填满整个盒子,所以它可能是较小的。但是,它不应该比其父母大100dp,这样留言的发送时间就有空间。
这是我的布局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingRight="@dimen/horizontalMargin"
android:paddingTop="10dp">
<TextView
android:id="@+id/message_holder"
android:layout_toLeftOf="@id/blank"
android:layout_alignParentLeft="true"
android:layout_marginLeft="@dimen/horizontalMargin"
android:background="@drawable/message_corners"
style="@style/white_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="alsdkjf; alsdkf" />
<RelativeLayout
android:id="@+id/blank"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_alignParentRight="true"
android:minWidth="100dp">
</RelativeLayout>
<TextView
android:minWidth="100dp"
android:id="@+id/time"
style="@style/gray_text"
android:layout_toRightOf="@id/message_holder"
android:paddingLeft="10dp"
android:text="Yesterday,\n11:30 PM" />
<RelativeLayout
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignBottom="@id/message_holder"
android:layout_alignParentLeft="true"
android:background="@drawable/triangle" />
</RelativeLayout>
我已经使用上的空白视图到消息框右侧提供间距“minWidth”属性试过了,但它并没有调整到较大(这将使该消息框更小)。当我没有空白视图时,只需将TextView放置到消息框的右侧,那么在消息框展开时该TextView不可见。
更新:
这是我的 “message_corners.xml”:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="@color/green" >
</solid>
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" >
</padding>
<corners
android:radius="10dp">
</corners>
</shape>
更新2:
这是我在简短的文字布局寻找:
这就是我在寻找的布局长文本:
你能解释一下吗?我正在设置消息框的最大宽度,但我不知道这个宽度是多少,因为它是为了填满整个屏幕。 –
添加的最大高度为message_holder TextView的 –
我觉得他不关心高度 – Bhargav