如何获得一个布局,其中一个文本可以成长,ellipsize,而不是吞噬其他元素的布局 [英] How to get a layout where one text can grow and ellipsize, but not gobble up the other elements on the layout

查看:98
本文介绍了如何获得一个布局,其中一个文本可以成长,ellipsize,而不是吞噬其他元素的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过一些其他职位在这里,如<一个href="http://stackoverflow.com/questions/3785221/two-textviews-side-by-side-only-one-to-ellipsize">Two TextViews并肩,唯一一个ellipsize?但我仍然有我的布局问题。

I've read some of the other posts here such as Two TextViews side by side, only one to ellipsize? but I'm still having an issue with my layout.

我有一个列表项的布局,我想在列表中的每个项目看起来是这样的:

I have a list item layout, and I want each item in the list to look like this:

| (扩展的TextView#1)(TextView的#2)                                                          (Image) |

| (Expanding TextView #1) (TextView #2)                                                          (Image) |

TextView的#2和图像必须始终显示。

TextView #2 and Image must always be visible.

现在,我使用了以下布局:

Right now I'm using the following layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainItem"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:background="@drawable/myBackground"
android:onClick="onClick"
android:longClickable="true">
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="80dp"
    android:layout_gravity="center_vertical|left"
    android:gravity="center_vertical|left"
    android:layout_toLeftOf="@+id/myImage"
    android:layout_alignParentLeft="true">
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="14dp"
        android:singleLine="true"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="0"/>
     <TextView
        android:id="@+id/testView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>    
 <ImageView
    android:id="@+id/myImage"
    android:layout_width="wrap_content"
    android:layout_height="80dp"
    android:layout_gravity="center_vertical"
    android:layout_alignParentRight="true"
    android:paddingRight="14dp"
    android:onClick="onClick"
    android:src="@drawable/myIcon"/>
</RelativeLayout>

我已经从,添加layout_weight =1的TextView#1将迫使TextView的#2的其他职位读被示出,并且是这样,但问题是,这种力的TextView#2是右对准因为它会导致的TextView#1以展开,即使它不必

I've read from the other posts that adding a layout_weight="1" to TextView#1 will force TextView #2 to be shown, and it does, but the problem is that this forces TextView #2 to be right-aligned because it causes TextView #1 to expand even when it doesn't have to.

我是pretty的现在难倒这个...任何人都可以帮助吗? :)

I'm pretty stumped on this now... could anyone help? :)

更新

我可以用一个TableLayout解决这一问题而收缩和放大器;伸展列属性。通过与它终于摸索我想它的方式玩了。

I was able to fix this by using a TableLayout and the shrink & stretch column properties. By playing around with that it finally worked the way I wanted it to.

推荐答案

如果我是你,我想大概是从LinearLayout中切换行RelativeLayout的,这样你可以调整图像到父权,屁股textview2直到旁边它,只是对齐textview1与离开亲和它可以调整,而不会影响其他两个字段

If I were you I'd probably switch the row from LinearLayout to RelativeLayout, that way you can align image to the parent right, butt textview2 right up next to it and just align textview1 with the parent left and it can resize without affecting the other two fields.

这篇关于如何获得一个布局,其中一个文本可以成长,ellipsize,而不是吞噬其他元素的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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