首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >并排查看,动态大小

并排查看,动态大小
EN

Stack Overflow用户
提问于 2016-08-18 13:49:04
回答 1查看 50关注 0票数 0

我试着并排放置三个视图: text1 - img - text2。Img必须始终在text1 (没有额外的空间)。我试图使用布局权重来解决这个问题,但是使用该解决方案,img总是位于父视图的中心。

预期结果:

Text1 short,Text2 long.不要在Text1和img之间添加空间

代码语言:javascript
复制
+----------------------------------------+
| [Text1 a] [img] [Text2 asdfghjklz... ] |
+----------------------------------------+

两个文本都是椭圆形的,保持img中心

代码语言:javascript
复制
+----------------------------------------+
| [Text1 asdfg...] [img] [Text2 asdf...] |
+----------------------------------------+

Text1 long,text2 short

代码语言:javascript
复制
+----------------------------------------+
| [Text1 asdfgadfafs...] [img] [Text2 a] |
+----------------------------------------+

这是我能得到的最接近的(使用权重),但问题是,如果text1是短的,则img仍然处于布局的中心。我应该一直站在text1的右边。

代码语言:javascript
复制
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/textview1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ellipsize="end"
        android:maxLines="1"
        tools:text="Text1 asdfghjkl" />

    <ImageView
        android:id="@+id/img"
        android:layout_width="18dp"
        android:layout_height="18dp"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:src="@drawable/ic_arrow" />

    <TextView
        android:id="@+id/textview2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ellipsize="end"
        android:maxLines="1"
        tools:text="Text2 asdfghjkl" />

</LinearLayout>
EN

回答 1

Stack Overflow用户

发布于 2016-08-18 14:25:16

使用相对布局,将每个小部件对齐到另一个小部件的右侧。对于第一个文本视图,给出一些宽度,然后添加以下2行

Android:ellipsize=“结束”android:maxLines=1“

对于图像,请使用所需的高度和宽度。

对于第三个文本视图,请使用下面的代码。对于这个文本视图,您不必设置可以使用包装内容的宽度。

Android:ellipsize=“结束”android:maxLines=1“

希望这会有所帮助,或者至少这将是一个好的开始。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39019956

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档