【发布时间】:2018-06-21 13:32:21
【问题描述】:
我有这个布局:
<?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);
}
【问题讨论】:
标签: android android-animation android-linearlayout android-relativelayout