zoukankan      html  css  js  c++  java
  • ConstraintLayout

    ConstraintLayout 继承自ViewGroup。
    1、约束类型:
    相对定位
     
    允许将指定的控件添加约束条件
    • 水平轴:left 、right、start、end
    • 垂直轴:   top、bottom、text baseline
    可用约束:
    • layout_constraintLeft_toLeftOf
    • layout_constraintLeft_toRightOf
    • layout_constraintRight_toLeftOf
    • layout_constraintRight_toRightOf
    • layout_constraintTop_toTopOf
    • layout_constraintTop_toBottomOf
    • layout_constraintBottom_toTopOf
    • layout_constraintBottom_toBottomOf
    • layout_constraintBaseline_toBaselineOf
    • layout_constraintStart_toStartOf
    • layout_constraintEnd_toStartOf
    • layout_constraintEnd_toEndOf 
      <?xml version="1.0" encoding="utf-8"?>
      <android.support.constraint.ConstraintLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent">
      
          <Button
              android:id="@+id/button2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="A"
      />
      
          <Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginStart="8dp"
              android:layout_marginTop="136dp"
              android:text="B"
              app:layout_constraintLeft_toRightOf="@+id/button2"
      />
      
      </android.support.constraint.ConstraintLayout>

      按钮B 的 左侧约束到按钮A的右侧

      2、边距
      当位置约束目标为View.GONE ,以下属性指示生效
      • layout_goneMarginStart
      • layout_goneMarginEnd
      • layout_goneMarginLeft
      • layout_goneMarginTop
      • layout_goneMarginRight
      • layout_goneMarginBottom
       
      3、定位

      居中

      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toRight="parent"

      居中偏移定位

      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintLeft_toRightOf="parent"
      //水平居中往左偏移  0-1
      app:layout_constraintHorizontal_bias="0.2"
      //垂直偏移
      app:layoutapp:layout_constraintVertical_bias="0.2"
      圆弧定位
      使用角度和距离,约束控件B相对于控件A的中心
      app:layout_constraintCircle="@+id/button2"
      app:layout_constraintCircleRadius="100dp"
      //角度0-360
      app:layout_constraintCircleAngle="120"
  • 相关阅读:
    android studio 模拟器控制台发送短信和定位
    android获取超级权限
    android拦截获取别人发送过来的短信
    stackflow看到的获取手机联系人 contact 的代码
    surfaceview绘制矩形 drawRect
    Dialog自定义setView按钮点击没反应
    腾讯移动端性能测试利器PerfDog使用
    Mac下第一个Python程序:HelloWorld
    Mac 系统下安装 PyCharm 的实践
    如何用Chrome浏览器打开Axure原型的start.html文件
  • 原文地址:https://www.cnblogs.com/changeMsBlog/p/11256468.html
Copyright © 2011-2022 走看看