不知道这样的布局该怎么描述,标题也是乱取的。。直接上图吧

最近遇到了这样要求的布局:

1、上图中的“标题”长度不定,“状态”标签可能有多个并紧跟在标题右边,“属性”一直居右显示;

2、当“标题”过长,一行显示不下时,“标题”换行显示,但不能挤掉“状态”和“属性”。

刚开始用了LinearLayout和RelativeLayout的多层嵌套总算是强行实现,但是嵌套太深了,而且代码看着也相当复杂,所以修改为用TableLayout,利用shrinkColumns和stretchColumns保证跟随的视图不被挤掉。

当然还有一个问题没解决:固定居右的“属性”一直没能放进TableLayout里,尝试设置“属性”为 stretchColumns + match_parent + gravity: right,放到TableRow的最后,但是没有效果,所以这里才套了层RelativeLayout,如果有办法能把RelativeLayout这层都省去,麻烦大家告诉我下~

 <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"> <TableLayout
android:id="@+id/table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/txvCreateTime"
android:shrinkColumns="0"
android:stretchColumns="1|2"> <TableRow android:gravity="center_vertical"> <TextView
android:id="@+id/txvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="居左居左居左居左居左居左"
android:textColor="@android:color/black"
android:textSize="@dimen/dimens_16_sp"
android:textStyle="bold" /> <TextView
android:id="@+id/txvState1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dimens_5_dp"
android:background="@drawable/layout_bg_orange"
android:paddingBottom="@dimen/dimens_2_dp"
android:paddingLeft="@dimen/dimens_5_dp"
android:paddingRight="@dimen/dimens_5_dp"
android:paddingTop="@dimen/dimens_2_dp"
android:singleLine="true"
android:text="跟随"
android:textColor="@android:color/white"
android:textSize="@dimen/dimens_12_sp" /> <TextView
android:id="@+id/txvState2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dimens_5_dp"
android:background="@drawable/layout_bg_orange"
android:paddingBottom="@dimen/dimens_2_dp"
android:paddingLeft="@dimen/dimens_5_dp"
android:paddingRight="@dimen/dimens_5_dp"
android:paddingTop="@dimen/dimens_2_dp"
android:singleLine="true"
android:text="跟随"
android:textColor="@android:color/white"
android:textSize="@dimen/dimens_12_sp" />
</TableRow>
</TableLayout> <TextView
android:id="@+id/txvCreateTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/dimens_5_dp"
android:gravity="center"
android:text="居右"
android:textColor="#999999"
android:textSize="@dimen/dimens_14_sp" />
</RelativeLayout>

阅读原文

Android布局:宽度适应的横向跟随,防止挤掉重要视图的更多相关文章

  1. Android布局优化:include 、merge、ViewStub的详细总结

    版权声明:本文出自汪磊的博客,未经作者允许禁止转载. 本篇博客主要是对上篇博客的补充Android性能优化之UI渲染性能优化, 没有什么新东西,觉得应该是都掌握的玩意,写出来也只是自己做个小小的总结. ...

  2. Android布局中的空格以及占一个汉字宽度的空格的实现

    在Android布局中进行使用到空格,以便实现文字的对齐.那么在Android中如何表示一个空格呢? 空格:  窄空格:  一个汉字宽度的空格:   [用两个空格(  )占一个汉字的宽度时,两个空格比 ...

  3. Android布局中的空格以及占一个汉字宽度的空格,实现不同汉字字数对齐

    前言 在Android布局中进行使用到空格,以便实现文字的对齐.那么在Android中如何表示一个空格呢? 空格: (普通的英文半角空格但不换行) 窄空格:   (中文全角空格 (一个中文宽度))   ...

  4. Android 布局简要范例

    Android的布局决定着实际的UI界面呈现情况,正是这些UI界面的组合与千变万化,才呈现出了各式各样的风格. 而这些基础的布局框架结构很重要,需要玩的很熟悉.我将以前参考的部分代码示例,所做的相关实 ...

  5. Android 布局管理器

    为了更好地管理Android应用程序的用户界面组件,Android它提供了一个布局管理.通过使用布局管理,Android具有良好的平台无关的图形用户界面应用程序. 平时,推荐布局管理器来管理分布式组件 ...

  6. Android布局及属性归总(查询用)

    常见布局 LinearLayout    线性布局        子元素任意,组织成一个单一的水平或垂直行,默认为水平方向TableLayout    表格布局        子元素为<Tabl ...

  7. [转]HorizontalScrollView介绍--支持水平滚动的android布局容器

    类概述 用 于布局的容器,可以放置让用户使用滚动条查看的视图层次结构,允许视图结构比手机的屏幕大.HorizontalScrollView是一种 FrameLayout(框架布局),其子项被滚动查看时 ...

  8. Android 布局之TableLayout

    Android 布局之TableLayout 1 TableLayout简介 TableLayout是表格布局.TableLayout 可设置的属性包括全局属性及单元格属性. 1.1 全局属性 有以下 ...

  9. Android 布局之FrameLayout

    Android 布局之FrameLayout 1 FrameLayout简介 对于FrameLayout,官方介绍是:FrameLayout is designed to block out an a ...

随机推荐

  1. C# BitArray 二进制处理

    int k = 6; byte[] bytearr = BitConverter.GetBytes(k); BitArray myBA = new BitArray(bytearr); for (in ...

  2. IntelliJ IDEA2017 + tomcat 即改即生效 实现热部署

    https://www.cnblogs.com/1024zy/p/6344000.html

  3. 跟踪SQL

    在数据库中,找到以下页面,并选择事件中的Tsql下的bath...与stm...

  4. list常用方法

    1.切片: ①.顾头不顾尾,从头开始取,但不包括最后一个. ②.从左向右数为正,从零开始,从右开始为负,从-1开始 如: names=['1','2','3'] ames[-1]与names[2]效果 ...

  5. oracle创建新用户和用户表空间

    .首先,创建(新)用户: create user username identified by password; username:新用户名的用户名 password: 新用户的密码 也可以不创建新 ...

  6. 09-JS的事件流的概念(重点)

    在学习jQuery的事件之前,大家必须要对JS的事件有所了解.看下文 事件的概念 HTML中与javascript交互是通过事件驱动来实现的,例如鼠标点击事件.页面的滚动事件onscroll等等,可以 ...

  7. Jquery 在子页面上设置父页面元素的值

    使用情景:因为我父页面上有用art.dialog,而子页面上有项目中的框架弹出方法跟art.dialog冲突,不能使用art.dialog自带的方法传值, 所以只好用一种简单粗暴的方法来设置. var ...

  8. Mapreduce操作HBase

    这个操作和普通的Mapreduce还不太一样,比如普通的Mapreduce输入可以是txt文件等,Mapreduce可以直接读取Hive中的表的数据(能够看见是以类似txt文件形式),但Mapredu ...

  9. text-decoration:[ text-decoration-line ] || [ text-decoration-style ] || [ text-decoration-color ] 默认值:

    css3中字体装饰,多样化的界面效果,: [ text-decoration-line ]:指定文本装饰的种类.相当于CSS2.1的 text-decoration 属性, 可取值:none | un ...

  10. Product and Sum in Category Theory

    Even if you are not a functional programmer, the notion of product type should be familiar to you, e ...