Android的长推TextView的其他视图关闭屏幕 [英] Long Android TextView pushes other views off-screen

查看:205
本文介绍了Android的长推TextView的其他视图关闭屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个TextViews并排侧。 TextView1有文字的不同长度和TextView2总是说+#。当TextView1得到长期然而,它推动TextView2关闭屏幕。任何想法如何解决这一问题?这里是我的布局code:

 < RelativeLayout的
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        机器人:方向=横向>        <的TextView
            机器人:ID =@ + ID / TextView1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:单线=真
            机器人:ellipsize =结束
            机器人:TEXTSIZE =13SP/>        <的TextView
            机器人:ID =@ + ID / TextView2
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:单线=真
            机器人:TEXTSIZE =13SP/>    < / RelativeLayout的>


解决方案

这其实是东西我试图解决现在一段时间。不幸的是,该方法其他人所说 - 使用 layout_weight 的LinearLayout - 实际上并没有工作;不过,我已经找到了解决方案,为您服务!

 < RelativeLayout的
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:重力=左>    <的TextView
        机器人:ID =@ + ID / TextView1
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_toLeftOf =@ ID / TextView2
        机器人:单线=真
        机器人:ellipsize =结束
        机器人:TEXTSIZE =13SP/>    <的TextView
        机器人:ID =@ + ID / TextView2
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentRight =真
        机器人:单线=真
        机器人:TEXTSIZE =13SP/>
< / RelativeLayout的>

通过上面的块,我们使用了 RelativeLayout的,以第一个的TextView 对齐的左第二个的TextView 。我们还调整了第二个的TextView 父右侧的ViewGroup 。最后,我们添加安卓重力=,以便使所有的<左的ViewGroup code>的TextView的左侧。

这导致两个的TextView 的并排存在一面 - 不管第一个的TextView 的长度。如果你想第一个的TextView 来有多条线路,只需删除的android:ellipsize =结束标记。

希望这是你期望的结果!

I've got two TextViews side-by-side. TextView1 has a varying length of text, and TextView2 always says "+#". When TextView1 gets long however, it pushes TextView2 off screen. Any ideas how to fix this? Here's my layout code:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/TextView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:ellipsize="end"
            android:textSize="13sp"/>

        <TextView
            android:id="@+id/TextView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:textSize="13sp"/>

    </RelativeLayout>

解决方案

This is actually something I've tried to solve for a while now. Unfortunately, the method others have suggested - using layout_weight inside LinearLayout - doesn't actually work; however, I've found a solution for you!

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="left">

    <TextView
        android:id="@+id/TextView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@id/TextView2"
        android:singleLine="true"
        android:ellipsize="end"
        android:textSize="13sp"/>

    <TextView
        android:id="@+id/TextView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:singleLine="true"
        android:textSize="13sp"/>
</RelativeLayout>

With the above block, we use a RelativeLayout in order to align the first TextView to the left of the second TextView. We also align the second TextView to the right side of the parent ViewGroup. Finally, we add android:gravity="left" to the parent ViewGroup in order to align all of the TextView's to the left.

This results in both TextView's being side by side - regardless of the first TextView's length. If you would like the first TextView to have multiple lines, simply remove the android:ellipsize="end" tag.

Hopefully this is your expected outcome!

这篇关于Android的长推TextView的其他视图关闭屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆