ConstraintLayout约束布局——实现左文右图效果

先来看下想要的效果:
左文右图,标题最多显示2行,时间和图片底部对齐
左文右图效果

1、问题说明: 在这个布局中,左边的文字和时间是一个整体,右边的图片是一个整体,让图片只位于文字右侧或者时间右侧都是不对的。
(1)图片位于文字右侧:当文字较少时,时间可能会遮挡图片。
(2)图片位于时间右侧:当文字较多时,文字可能会遮挡图片。

在这里插入图片描述

对应代码如下:

 <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:paddingTop="10dp"
        android:paddingBottom="10dp"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        app:layout_constraintVertical_bias="0.9"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent">


        <ImageView
            android:id="@+id/img"
            android:layout_width="100dp"
            android:layout_height="70dp"
            android:scaleType="centerCrop"
            android:src="@drawable/test_img"
            app:layout_constraintLeft_toRightOf="@+id/time"/>

        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="标题标题标题标题标题标题题标题标题标题标题标题题标题标题"
            android:maxLines="2"
            android:ellipsize="end"
            app:layout_constraintLeft_toLeftOf="parent"/>

        <TextView
            android:id="@+id/time"
            android:layout_width=&#
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值