美文网首页
android ConstraintLayout 剪辑

android ConstraintLayout 剪辑

作者: 小菜_charry | 来源:发表于2018-02-07 14:08 被阅读32次

1. 对其方式

例如:app:layout_constraintLeft_toRightOf="parent"
解释:当前控件左边 与 夫控件的右边 对其

app:layout_constraintLeft_toLeftOf="parent" // 也可以是其他控件的 id
app:layout_constraintLeft_toRightOf="@id/guideline_h"
app:layout_constraintRight_toLeftOf="@id/tv"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"

2. 控制偏移

当对其好了后可以设置偏移量

// 偏移
app:layout_constraintVertical_bias="0.9" // 移到垂直方向的 90% 位置
app:layout_constraintHorizontal_bias="0.8"

3. 控制宽高比

// 设置宽高比  
app:layout_constraintDimensionRatio="16:6"  // 默认 宽:高
app:layout_constraintDimensionRatio="W,16:6"
app:layout_constraintDimensionRatio="H,16:6"

4. 链的样式

左边对其左边控件的右边,右边对其右控件的左边时

// 当控件形成链时(左边对其左边控件的右边,右边对其右控件的左边时),可以设置其链的样式
app:layout_constraintHorizontal_chainStyle="packed"  // spread_inside  spread
app:layout_constraintVertical_chainStyle="spread"

5. 权重比

在链式布局好后可以设置权重

// 权重比
app:layout_constraintHorizontal_weight="2"
app:layout_constraintVertical_weight="2"

一个链式布局例子:

  // 布局方式:
  <TextView
      android:id="@+id/tab1"
      android:layout_width="0dp"
      android:layout_height="30dp"
      android:background="#f67"
      android:gravity="center"
      android:text="Tab1"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintRight_toLeftOf="@+id/tab2" />
  <TextView
      android:id="@+id/tab2"
      android:layout_width="0dp"
      android:layout_height="30dp"
      android:background="#A67"
      android:gravity="center"
      android:text="Tab2"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toRightOf="@id/tab1"
      app:layout_constraintRight_toLeftOf="@+id/tab3" />
  <TextView
      android:id="@+id/tab3"
      android:layout_width="0dp"
      android:layout_height="30dp"
      android:background="#767"
      android:gravity="center"
      android:text="Tab3"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintLeft_toRightOf="@id/tab2"
      app:layout_constraintRight_toRightOf="parent" />

6. Guideline 的使用

Guideline 放在哪都可以

<android.support.constraint.Guideline
 android:id="@+id/guideline_h"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:orientation="horizontal" // vertical
 app:layout_constraintGuide_percent="0.5" /> // 在 50% 的位置
// 其他属性
layout_constraintGuide_begin
layout_constraintGuide_end
layout_constraintGuide_percent

参考
http://blog.csdn.net/lmj623565791/article/details/78011599
http://blog.csdn.net/guolin_blog/article/details/53122387

相关文章

网友评论

      本文标题:android ConstraintLayout 剪辑

      本文链接:https://www.haomeiwen.com/subject/vknozxtx.html