[英]Textview2 is not showm when TextView1 have more than one line
I have some problem when Textview1 have more than one line. 当Textview1有多行时,我遇到一些问题。
Example: textview1 have one line, textview2 is shown. 示例:textview1有一行,显示了textview2。
But if textview1 have more than one line, textview2 is not shown because textview1 is full. 但是,如果textview1包含多行,则不会显示textview2,因为textview1已满。
And my .xml: 而我的.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>
How to fix it? 如何解决?
In case of having textviews side by side its always recommended to use Linear Layout with weight = 1 for both the textviews. 如果并排使用textview,则始终建议对两个textview使用线形布局,权重= 1。
Try this : 尝试这个 :
<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>
wrap your textviews as tablerow. 将您的textviews包装为tablerow。
<?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"/>
<TableRow
android:weightSum="1"
android:layout_marginLeft="10dp"
android:layout_toRightOf="@+id/img_vote"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_weight=".60" // here manage the weight/percentage
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="xxxxxxdfkldjsklfjsdxxxxxx"
android:id="@+id/tx_poll"/>
<TextView
android:layout_weight=".40"// here manage the weight/percentage
android:layout_width="0dp"
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:background="@drawable/bg_count_poll"
android:gravity="center"
android:paddingLeft="5dp"
android:paddingRight="5dp"/>
</TableRow>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Do it like this 像这样做
<?xml version="1.0" encoding="utf-8"?>
<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"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_toRightOf="@+id/img_vote"
android:weightSum="2">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="xxxxxxdfkldjsklfjsdxxxxxx"
android:id="@+id/tx_poll"
android:layout_marginLeft="10dp"
android:layout_weight="1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ttt"
android:id="@+id/tx_count_vote"
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_weight="1"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
That's because you have android:layout_height="wrap_content
" on your android:id="@+id/tx_poll"
. 那是因为您的android:id="@+id/tx_poll"
上有android:layout_height="wrap_content
android:id="@+id/tx_poll"
。 When there is a lot of text it shifts your android:id="@+id/tx_count_vote"
and it becomes invisible. 当文本很多时,它将移动您的android:id="@+id/tx_count_vote"
并变为不可见。
You have this options: 您有以下选择:
Add fixed size for tx_poll
TextView. 为tx_poll
TextView添加固定大小。 Something like: android:layout_width="90dp"
类似于: android:layout_width="90dp"
Use LinearLayout with layout_weight
结合使用LinearLayout和layout_weight
在tx_poll中设置属性android:layout_toLeftOf =“ @ + id / tx_count_vote”,还可以设置textView的maxLength以防止重叠和固定tx_poll textView的区域
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.