当 Textview1 有多于一行时,我遇到了一些问题。
示例:textview1 有一行,textview2 显示。
但如果 textview1 有多于一行,则 textview2 不会显示,因为 textview1 已满。
还有我的 .xml:
<?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="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:padding="5dp"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_marginTop="10dp">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:id="@+id/img_vote"
android:src="@drawable/vote_t_1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="xxxxxxdfkldjsklfjsdxxxxxx"
android:id="@+id/tx_poll"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/img_vote"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ttt"
android:id="@+id/tx_count_vote"
android:gravity="center"
android:textColor="@color/color_white"
android:textSize="@dimen/tx_size_smally"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:background="@drawable/bg_count_poll"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/tx_poll"/>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
如何解决?
如果将文本视图并排放置,始终建议对两个文本视图使用权重 = 1 的线性布局。
试试这个 :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/textViewprimary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="abcd" />
<TextView
android:id="@+id/textViewSecondary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="efgh" />
</LinearLayout>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句