Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当TextView1有多行时,Textview2不显示_Android_Xml_Textview - Fatal编程技术网

Android 当TextView1有多行时,Textview2不显示

Android 当TextView1有多行时,Textview2不显示,android,xml,textview,Android,Xml,Textview,当Textview1有多行时,我遇到一些问题 示例:textview1只有一行,显示textview2 但如果textview1有多行,则不会显示textview2,因为textview1已满 和my.xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_

当Textview1有多行时,我遇到一些问题

示例:textview1只有一行,显示textview2

但如果textview1有多行,则不会显示textview2,因为textview1已满

和my.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>


如何修复它?

将文本视图包装为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>

将文本视图包装为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>

像这样做

<?xml version="1.0" encoding="utf-8"?>


像这样做

<?xml version="1.0" encoding="utf-8"?>



这是因为您的
android:id=“@+id/tx\u poll”
上有
android:layout\u height=“wrap\u content
。当有大量文本时,它会移动您的
android:id=“@+id/tx\u count\u vote”
,并且它变得不可见

您有以下选项:

  • tx\u poll
    TextView添加固定大小。类似于:
    android:layout\u width=“90dp”

  • 将线性布局与布局重量一起使用

  • 使用


  • 这是因为您的
    android:id=“@+id/tx\u poll”
    上有
    android:layout\u height=“wrap\u content
    ”。当有大量文本时,它会移动您的
    android:id=“@+id/tx\u count\u vote”
    ,并且它变得不可见

    您有以下选项:

  • tx\u poll
    TextView添加固定大小。类似于:
    android:layout\u width=“90dp”

  • 将线性布局与布局重量一起使用

  • 使用


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

    设置属性android:layou toLeftOf=“@+id/tx_count_vote”在tx_poll中,您还可以设置textView的maxLength,以防止tx_poll textView的区域重叠和固定,如果textView并排出现,则始终建议对两个textView使用权重为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>
    

    如果文本视图并排,则始终建议对两个文本视图使用权重为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>
    
    
    

    在文本视图上使用省略号这里使用相对布局有什么特别的原因吗。我通常更喜欢在这样的情况下使用线性布局。您可以将
    表行
    线性布局
    与权重属性一起使用。@srbban如何使用它,请举例说明me@ARR.s查看答案。在文本视图上使用省略号是否有任何特殊原因使您在此处使用相对布局。我通常更喜欢在这样的情况下使用线性布局。您可以将
    表行
    线性布局
    与权重属性一起使用。@srbban如何使用它,请举例说明me@ARR.s查看答案。谢谢,但是如果某个时候textview只有一行,那么设置textview对我来说是个问题(我想在textview1之后设置textview2)它将始终位于textview 1的右侧。嗯,但我希望textview 2位于textview 1Thanks中的最后一个文本之后,但如果有时textview只有一行,这对我来说是设置textview的问题(我想在textview 1之后设置textview 2)它将始终位于textview 1右侧的后面。嗯,但我希望textview 2位于textview 1 Hanks中最后一个文本的后面!如果两个文本视图的chage-weight=1,则不起作用,但仅将android:layout_-weight=“1”更改为textview1,则起作用!是的,这就是我的意思,我只是粗略地说了重量。为了说明我的意思,我粘贴了代码,上面写着“android:layout_weight”。我很高兴它有帮助:-)谢谢!如果两个文本视图的chage-weight=1,则不起作用,但仅将android:layout_-weight=“1”更改为textview1,则起作用!是的,这就是我的意思,我只是粗略地说了重量。为了说明我的意思,我粘贴了代码,上面写着“android:layout_weight”。我很高兴这有帮助:-)