2017-01-05 4 views
1

私はCollapseingToolbarLayoutの中にImageViewを持っていて、ImageViewは画面の下にいくつかの情報を表示します。ユーザーがImageViewをクリックすると、CollapsingToolBarLayoutの高さが150dpになります。どのように滑らかなアニメーションを150dpの高さに設定するために、CollapsingToolBarLayoutの高さを設定しますか?私は滑らかに、そしてゆっくりと高さを150dpにしていいのですが、すばらしいアニメーションがあります。 これをどのように達成できますか?スムーズにレイアウトの高さを設定する方法

activity_scrolling.xmlは

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
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:fitsSystemWindows="true" 
tools:context="com.myapplication.foodapp.ScrollingActivity" 
android:id="@+id/coordinator_layout" 
android:animateLayoutChanges="true"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    android:theme="@style/AppTheme.PopupOverlay" 
    android:animateLayoutChanges="true"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_tool_bar_layout" 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:fitsSystemWindows="true" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed" 
     android:animateLayoutChanges="true"> 

     <ImageView 
      android:id="@+id/chipotle_image" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_alignParentTop="true" 
      android:layout_gravity="fill_vertical" 
      android:src="@mipmap/food1" 
      android:adjustViewBounds="true" 
      android:scaleType="fitXY"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Chipotle Chicken Fajitas" 
      android:textSize="27sp" 
      android:layout_gravity="bottom" 
      android:layout_marginBottom="40dp" 
      android:layout_marginLeft="5dp" 
      android:textColor="#fff" 
      android:id="@+id/first_food_title"/> 

     <me.grantland.widget.AutofitTextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="16 ingredients | 284 Calories | 1 hour" 
      android:singleLine="true" 
      android:textAlignment="center" 
      android:textColor="#fff" 
      android:layout_gravity="bottom" 
      android:textSize="20sp" 
      android:id="@+id/spec_text"/> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      app:layout_collapseMode="pin" 
      android:animateLayoutChanges="true"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <ImageView 
        android:layout_width="25dp" 
        android:layout_height="25dp" 
        android:src="@mipmap/arrow" 
        android:id="@id/back_Arrow" 
        android:layout_marginTop="5dp" 
        /> 




      </LinearLayout> 


     </android.support.v7.widget.Toolbar> 




    </android.support.design.widget.CollapsingToolbarLayout> 

</android.support.design.widget.AppBarLayout> 

<!-- ** CONTENT SCROLLING LAYOUT ** --> 
<include layout="@layout/content_scrolling"> 

</include> 
</android.support.design.widget.CoordinatorLayout> 

答えて

0

あなたはValueAnimatorでこれを達成することができます。

ValueAnimator anim = ValueAnimator.ofInt(viewToIncreaseHeight.getMeasuredHeight(), finalValue); 
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 
    @Override 
    public void onAnimationUpdate(ValueAnimator valueAnimator) { 
     int val = (Integer) valueAnimator.getAnimatedValue(); 
     ViewGroup.LayoutParams layoutParams = viewGroup.getLayoutParams(); 
     layoutParams.height = val; 
     viewGroup.setLayoutParams(layoutParams); 
    } 
}); 
anim.start(); 
関連する問題