假设有四个TextViews
并且最右边有一个菜单图标:
one two three four menu icon
在第四篇文章中,文字将是这样的:
Krishanu Das(one) shared(two) avoy roy(three) 's post(four)
这意味着文字是
Krishanu Das shared avoy roy 's post
有时会是
Krishanu Das(one) 's post(two)
然后另外两个TextViews
将是Gone / Invisible。
我的问题是,只要两个TextViews
[1&增加了三个,它触及位于最右侧的菜单图标。
我正在使用wrap_content
这四个TextViews
。
我希望每当用户的名字长度增加时,TextViews
会自动溢出到多行。
以下是我的布局现在的样子:
这是我的标题设计代码:
<TextView
android:id="@+id/post_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="postheader1"
android:textStyle="bold"
android:textColor="#103c60" />
<TextView
android:id="@+id/post_header_2ndpart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="10dp"
android:text="'s Post"
android:layout_toRightOf="@+id/post_header"
android:layout_below="@+id/post_headerdown_view"
android:textColor="#000" />
<RelativeLayout
android:id="@+id/shedHeader_rltv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/post_header_2ndpart"
android:layout_below="@+id/post_headerdown_view"
android:layout_marginLeft="4dp"
android:layout_marginTop="10dp"
android:visibility="visible"
>
<TextView
android:id="@+id/oneUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="postheader2"
android:textStyle="bold"
android:textColor="#103c60" />
<TextView
android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="'s Post"
android:layout_toRightOf="@+id/oneUserName"
android:textColor="#000" />
</RelativeLayout>
<TextView
android:id="@+id/post_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="Menu"
android:padding="6dp"
android:layout_alignParentRight="true"
android:layout_below="@+id/post_headerdown_view"
android:textColor="#103c60" />
答案 0 :(得分:0)
只需将所有textview合并到一个RelativeLayout
中,然后将它们与Menu
按钮对齐。 XML代码是:
<RelativeLayout
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_toLeftOf="@+id/post_menu" >
<TextView
android:id="@+id/post_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="postheader1"
android:textStyle="bold"
android:textColor="#103c60" />
<TextView
android:id="@+id/post_header_2ndpart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="10dp"
android:text="'s Post"
android:layout_toRightOf="@+id/post_header"
android:layout_below="@+id/post_headerdown_view"
android:textColor="#000" />
<RelativeLayout
android:id="@+id/shedHeader_rltv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/post_header_2ndpart"
android:layout_below="@+id/post_headerdown_view"
android:layout_marginLeft="4dp"
android:layout_marginTop="10dp"
android:visibility="visible">
<TextView
android:id="@+id/oneUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="postheader2"
android:textStyle="bold"
android:textColor="#103c60" />
<TextView
android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="'s Post"
android:layout_toRightOf="@+id/oneUserName"
android:textColor="#000" />
</RelativeLayout>
</RelativeLayout>
<TextView
android:id="@+id/post_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="Menu"
android:padding="6dp"
android:layout_alignParentRight="true"
android:layout_below="@+id/post_headerdown_view"
android:textColor="#103c60" />