2017-01-05 3 views
1

CollapseingToolbarLayout 안에 ImageView가 있고 ImageView가 전체 화면의 일부 정보를 맨 아래에 표시합니다. 사용자가 ImageView를 클릭하면 CollapsingToolBarLayout 높이가 150dp이되고 싶습니다. smooth 애니메이션의 높이를 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();