ConstraintLayout外部的位置视图 [英] Position view outside of ConstraintLayout
问题描述
我想将视图放置在 ConstraintLayout
之外,以使用滑动动画对其进行动画处理.我试过设置诸如 constraintBottom_toTopOf ="parent"
之类的约束,但是 View
保留在容器内.
I want to position views outside of a ConstraintLayout
to animate them with a sliding animation. I've tried setting contraints like constraintBottom_toTopOf="parent"
but the View
stays inside the container.
请注意,我想通过使用内置动画而不是代码内动画的约束来实现这一目标.
Note that I want to achieve this with constraints to use built-in animations, not with in-code animations.
知道我该怎么做吗?
我正在使用 compile'com.android.support.constraint:constraint-layout:1.1.0-beta1'
与Android Studio 3.0 Beta 7
I'm using compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
with Android Studio 3.0 Beta 7
这是一个简单的xml文件,应将视图放置在容器之外:
This is a simple xml file that should place the view outside of the container :
<?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>
但这是结果
推荐答案
这似乎是 ConstraintLayout
1.1.0-beta1的问题;它可以在 ConstraintLayout
1.1.0-beta3中正常工作.
This appears to be an issue with ConstraintLayout
1.1.0-beta1; It works as expected in ConstraintLayout
1.1.0-beta3.
更新为 ConstraintLayout
1.1.0-beta3.我还将注意到,您需要通过执行以下操作来水平限制视图.
Update to ConstraintLayout
1.1.0-beta3. I will also note that you need to constrain your view horizontally by doing something like the following.
<View
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@color/colorPrimary"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toTopOf="parent" />
在旁注中, ConstraintLayout
中不接受负边距.请参阅此有关负边距和 ConstraintLayout
.
On a side note, negative margins are not accepted in ConstraintLayout
. See this Stack Overflow question regarding negative margins and ConstraintLayout
.
这篇关于ConstraintLayout外部的位置视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!