ConstraintLayout外部的位置视图

Dav*_*ssi 6 android android-constraintlayout

我想将视图放置在的外部,ConstraintLayout以使用滑动动画对其进行动画处理。我尝试过设置约束,例如,constraintBottom_toTopOf="parent"View停留在容器内。

请注意,我想通过使用内置动画而不是代码内动画的约束来实现这一目标。

知道我该怎么做吗?

我正在使用compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1' Android Studio 3.0 Beta 7

这是一个简单的xml文件,应将视图放置在容器之外:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/colorAccent">

    <View
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@color/colorPrimary"
        app:layout_constraintBottom_toTopOf="parent"/>


</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)

但这是结果
在此处输入图片说明

Che*_*amp 5

这似乎是ConstraintLayout1.1.0-beta1的问题;它在ConstraintLayout1.1.0-beta3 中按预期工作。

更新到ConstraintLayout1.1.0-beta3。我还将注意到,您需要通过执行以下操作来水平约束您的视图。

<View
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@color/colorPrimary"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintBottom_toTopOf="parent" />
Run Code Online (Sandbox Code Playgroud)

附带说明一下,.net 中不接受负边距ConstraintLayout。请参见关于切缘阴性和堆栈溢出问题ConstraintLayout