ConstraintLayout之外的位置视图
我想在ConstraintLayout
之外定位视图以使用滑动动画为其设置动画效果。我已经尝试设置像constraintBottom_toTopOf="parent"
这样的限制,但View
停留在容器内。ConstraintLayout之外的位置视图
请注意,我想通过约束来实现这一点,以使用内置动画,而不是使用代码内动画。
任何想法我可以做到这一点?
我使用compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
与Android Studio的3.0测试版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>
这似乎是一个问题ConstraintLayout
1.1.0-beta1;它在ConstraintLayout
1.1.0-beta3中按预期工作。
更新至ConstraintLayout
1.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" />
请注意,在ConstraintLayout
中不接受负边界。请参阅this有关负余量的堆栈溢出问题和ConstraintLayout
。
我接受了这个答案,因为它解决了这个问题,但是知道它带回了一个老问题,其中'ConstraintLayout'被搞乱了nestedScrollView –
@DavidSeroussi我很抱歉听到另一个问题已经出现。您可以发布一个问题来解决导致问题的XML的嵌套滚动视图问题。 – Cheticamp
在每个视图中,您都可以使用负边距,这会将视图置于父视图之外,然后设置裁切参数。
android:clipChildren="false"
android:clipToPadding="false"
这将使视图不剪辑。
我有另一种方式来解决这个问题:
1.增加一个锚(anchor_left
)layout_constraintStart_toStartOf="parent"
。
2.增加YourView
layout_constraintEnd_toStartOf="@+id/anchor_left"
这就是它!
代码:
<android.support.constraint.ConstraintLayout>
<View
android:id="@+id/anchor_left"
app:layout_constraintStart_toStartOf="parent"/>
<YourView
android:id="@+id/ll_left"
app:layout_constraintEnd_toStartOf="@+id/anchor_left"/>
</android.support.constraint.ConstraintLayout>
我从来没有尝试过,但约varing从0到1的偏见是什么? – Juan
请分享您的xml –
发布您正在使用哪个版本的'ConstraintLayout'。确保你没有定义额外的约束,将视图拉回布局。另外,查看XML会很有帮助。 – Cheticamp