我有这样的布局:
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/blue_pattern_repeated"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/layout_splash_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp"
>
<RelativeLayout
android:id="@+id/layout_splash_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="170dp"
>
<ImageView
android:id="@+id/ivLogo"
android:layout_width="match_parent"
android:layout_height="100dp"
app:srcCompat="@mipmap/logo_exa"
android:layout_alignParentTop="true"
/>
<LinearLayout
android:id="@+id/layout_loader_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="8dp"
android:layout_below="@+id/ivLogo"
>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
如何将@ + id / layout_splash_content发送到父母的顶部?
我有此幻灯片动画,但是在某些设备中,顶部位置无法正常工作,有时未与父级顶部对齐...
在一些主要活动中:
private void SlideUpLogo() {
Slide(layoutSplashContent, -0.65f, null);
}
在基本活动中:
protected void Slide(View view, float toYValue, Animation.AnimationListener listener) {
ViewGroup.LayoutParams viewLP = view.getLayoutParams();
ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams(viewLP);
TranslateAnimation ta = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, lp.topMargin,
Animation.RELATIVE_TO_SELF, toYValue);
ta.setDuration(500);
ta.setFillAfter(true);
ta.setAnimationListener(listener);
view.startAnimation(ta);
}
答案 0 :(得分:0)
这不是ConstraintLayout的工作方式。在约束布局的情况下,MATCH_PARENT不保留任何值。在上述情况下,布局“ @ + id / layout_splash_container”应如下所示,
<LinearLayout
android:id="@+id/layout_splash_container"
android:layout_width="0dp"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:padding="8dp">
将占据父级所有可用的宽度和高度。您也可以尝试将“相对”或“框架”布局用于简单结构。