это нелегко сделать анимацию через XML, потому что у Android столько экранов. Итак, во-первых, вам нужно рассчитать высоту относительной части макета и всю высоту экрана, тогда вы можете получить фактическую высоту, которую хотите поднять на экране, и сделать анимацию.
Ниже приведен пример кода:
Layout XML:
<LinearLayout
android:id="@+id/layout_order_types"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@+id/layout_mask"
android:visibility="invisible" >
<ImageView
android:id="@+id/image_all_order"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/all_order" />
..............
..............
</LinearLayout>
Код Активность:
// Whole screen height
int heightPixels = getApplicationContext().getResources().getDisplayMetrics().heightPixels;
View layoutOrderTypes = findViewById(R.id.layout_order_types);
layoutOrderTypes.setVisibility(View.VISIBLE);
// slide in from bottom animation
Animation inFromBottom = new TranslateAnimation(
Animation.ABSOLUTE, 0.0f,
Animation.ABSOLUTE, 0.0f,
Animation.ABSOLUTE, heightPixels,
Animation.ABSOLUTE, (heightPixels - layoutOrderTypes.getHeight()
- DisplayUtil.getStatusBarHeight(this)));
inFromBottom.setDuration(300);
// start the animation
layoutOrderTypes.startAnimation(inFromBottom);
DisplayUtil.java
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}