简体   繁体   English

当TextView1具有多行时,Textview2不是showm

[英]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: 您有以下选择:

  1. Add fixed size for tx_poll TextView. tx_poll TextView添加固定大小。 Something like: android:layout_width="90dp" 类似于: android:layout_width="90dp"

  2. Use LinearLayout with layout_weight 结合使用LinearLayout和layout_weight

  3. Use PercentRelativeLayout 使用PercentRelativeLayout

在tx_poll中设置属性android:layout_toLeftOf =“ @ + id / tx_count_vote”,还可以设置textView的maxLength以防止重叠和固定tx_poll textView的区域

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在此示例中,如何在Textview2顶部放置TextView1? - How in this example, can I have TextView1 on top of Textview2? 无法显示我的 Textview1 和 Textview2 之间的计算时间差? - Unable to show calculate Time difference between my Textview1 and Textview2? 单击按钮后,如何将textview1的值转换为textview2? - how can i get the value of textview1 into textview2 after click the button? 如何通过我的 textView1 从字符串资源中获取 textview2 getText 等于字符串名称 - How to textview2 getText from String resource by my textView1 is equal string name 当 TextView 中的 output 多于一行时,文本触及 Parent 的开头 - The Text touches the start of Parent when there is more than one line of output in TextView 向TextView添加多个String - Add more than one String to a TextView 如何将多个textView添加到listView - How to add more than one textView to listView 如果行数不止一个,如何在Android的TextView中的特定单词之前插入换行符? - How to insert a line break before specific word in TextView in Android, if line count is more than one? TextView1无法解析为一种类型 - TextView1 can't be resolved to a type Android:具有多行文本的TextView不可点击/长按可点击 - Android: TextView having text of more than one line is not clickable/long clickable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM