缩放View,直播带货源码是怎样实现按比例缩放的

直播带货源码实现按比例缩放View,关键点有两个,第一,使用Android ConstraintLayout的layout_constraintDimensionRatio属性,设置宽高比缩放比例,宽:高。第二,恒定宽和高,另外一个方向就会按照比例缩放。

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:id="@+id/text0"
            android:layout_width="0dp"
            android:layout_height="100dp"
            android:background="@android:color/holo_orange_light"
            android:gravity="center"
            android:text="w=0,h=100\n5:2"
            android:textColor="@android:color/white"
            android:textSize="10dp"
            app:layout_constraintDimensionRatio="5:2"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/text1"
            android:layout_width="100dp"
            android:layout_height="0dp"
            android:background="@android:color/holo_red_light"
            android:gravity="center"
            android:text="w=100,h=0\n5:2"
            android:textColor="@android:color/white"
            android:textSize="10dp"
            app:layout_constraintDimensionRatio="5:2"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toBottomOf="@id/text0" />
    </android.support.constraint.ConstraintLayout>

运行结果如图:

 如上,就可以简单实现直播带货源码按比例缩放View了 。

声明:本文由云豹科技转发自开开心心过博客,如有侵权请联系作者删除

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值