那是我的MainActivity
xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".views.activities.MainActivity">
<include
android:id="@+id/main_toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
layout="@layout/toolbar" />
<fragment
android:id="@+id/location_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/main_toolbar"
android:name="com.myapp.views.fragments.mainActivity.LocationSearchFragment"
android:tag="fragment_location_search"
tools:layout="@layout/fragment_location_search"
class="com.myapp.views.fragments.mainActivity.LocationSearchFragment" />
<fragment
android:id="@+id/restaurants_list_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/location_fragment"
android:name="com.myapp.views.fragments.mainActivity.RestaurantFragment"
android:tag="fragment_restaurant_list"
tools:layout="@layout/fragment_restaurant_list"
class="com.myapp.views.fragments.mainActivity.RestaurantFragment" />
</RelativeLayout>
当某些事件发生时(搜索已完成且要显示的数据)我想向上滑动location_fragment
和restaurants_list_fragment
,但保留自定义工具栏的位置。创建动画的代码如下所示:
public void onRestaurantsSearchCompleted(RestaurantSearchCompleted evt) {
View locationView = findViewById(R.id.location_fragment);
View restaurantsView = findViewById(R.id.restaurants_list_fragment);
RelativeLayout.LayoutParams restaurantsLayoutParams = new RelativeLayout.LayoutParams(restaurantsView.getWidth(), Defaults.restaurantsFragmentHeightAfterAnimation);
float slideUp = -Defaults.locationFragmentHiddenPartHeight;
locationView.animate()
.translationYBy(slideUp);
restaurantsView.animate()
.translationYBy(slideUp);
restaurantsView.setLayoutParams(restaurantsLayoutParams);
}
我现在正在努力解决的问题是,动画也会滑动我的自定义工具栏。如何防止这种情况发生?