【发布时间】:2018-03-27 23:52:49
【问题描述】:
我想将视图定位在 ConstraintLayout 之外,以使用滑动动画为它们设置动画。我尝试过设置 constraintBottom_toTopOf="parent" 之类的约束,但 View 保留在容器内。
请注意,我想通过使用内置动画的约束来实现这一点,而不是使用代码内动画。
知道我该怎么做吗?
我在 Android Studio 3.0 Beta 7 中使用 compile 'com.android.support.constraint:constraint-layout:1.1.0-beta1'
这是一个简单的 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>
【问题讨论】:
-
我从未尝试过,但是将偏差从 0 变为 1 怎么样?
-
请分享你的xml
-
发布您使用的
ConstraintLayout的版本。确保您没有定义将视图拉回布局的其他约束。此外,查看 XML 也会有所帮助。 -
我添加了xml和
ConstraintLayout版本 -
我能够通过设置填充和 clipToPadding="false" 来完成这项工作1. 当在 ConstraintLayout 的右/左边缘时,imageView 被剪成两半。通过将 ConstraintLayout 的 rightPadding 和 leftPadding 设置为 ImageView 宽度的一半,它不再被裁剪(并且百分比定位仍然有效)。
标签: android android-layout material-design android-view android-constraintlayout