2017-03-17 13 views
1

대화 상자 레이아웃에서 cachapa/ExpandableLayout을 사용하고 있는데 예기치 않은 애니메이션이 있습니다. 내 말은, 확장 가능한 레이아웃은 안으로 들어 가지 않고 부드럽게 움직이지만, 갑자기 나타납니다. 위의 사진을 볼 수 있듯이ExpandableLayout animation not smooth

Click to screen shot

, 나는 Utils.setWindowGravity(getWindow(), Gravity.BOTTOM);을 사용하여 화면의 하단에있는 대화 상자를 배치합니다. TOP으로 변경하면 애니메이션은 fine으로 작동합니다. 하지만 제 경우에는 BOTTOM으로 설정해야합니다. 어떻게 해결할 수 있습니까?

고해상도/레이아웃 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical"> 

    <!--other views--> 

    <net.cachapa.expandablelayout.ExpandableLayout 
     android:id="@+id/expand_add" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     app:el_duration="500" 
     app:el_expanded="false"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 

      <EditText 
       android:id="@+id/name" 
       style="@style/EditText_BorderedMiddle_Grey_F" 
       android:layout_width="match_parent" 
       android:layout_weight="1" 
       android:hint="@string/dialog_categories_hintname"/> 

      <ImageView 
       android:id="@+id/submit" 
       style="@style/ImageView_FilledMiddle_Blue_F_50" 
       android:src="@drawable/ic_check_white_48dp"/> 
     </LinearLayout> 
    </net.cachapa.expandablelayout.ExpandableLayout> 

    <!--other views--> 
</LinearLayout> 

자바

public class CategoriesDialog extends AppCompatDialog { 
    //other codes 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     Utils.setWindowGravity(getWindow(), Gravity.BOTTOM); 
     //... 
    } 
    @OnClick(R.id.add) 
    public void onAddClick() { 
     expandAdd.toggle(); 
    } 
} 

public class Utils { 
    public static void setWindowGravity(Window window, int gravity) { 
     WindowManager.LayoutParams attributes = window.getAttributes(); 
     attributes.gravity = gravity; 
     window.setAttributes(attributes); 
    } 
} 
+0

위로 가기 선형 레이아웃에서 animatelayoutchanges = true를 추가하려고합니다. –

+0

답장을 보내 주셔서 감사합니다. 나는 노력했지만 여전히 일하지 않습니다. –

+0

사용자 정의 클래스 코드 또는 라이브러리 의사 확인 –

답변

1

나는 그런 당신의 대화의 크기를 변경 할 좋은 아이디어라고 생각하지 않습니다. 내 자신의 경험에 비추어 볼 때, Dialog의 높이를 변경하는 것은 매우 비현실적이며, 애니메이션이 제대로 작동하고 있었다고해도 엄청나게 엉망입니다.

대신 전체 UI에 배치하는 사용자 정의 오버레이로 해당 인터페이스를 구현하는 것이 좋습니다. 당신의 ExpandableLayout을 닫 클릭 리스너 및 expansionRatio가 제로의 경우 전체 오버레이를 숨기는 ExpansionListener로

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/scrim" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#6000"> 

    <Button 
     android:id="@+id/add" 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:text="Add" /> 

    <net.cachapa.expandablelayout.ExpandableLayout 
     android:id="@+id/expand_add" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom" 
     android:orientation="vertical" 
     app:el_duration="500" 
     app:el_expanded="false" 
     app:el_parallax="0"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?android:windowBackground" 
      android:orientation="horizontal"> 

      <EditText 
       android:id="@+id/name" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="1" /> 

      <ImageView 
       android:id="@+id/submit" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/ic_chevron_right_black_48dp" /> 
     </LinearLayout> 

    </net.cachapa.expandablelayout.ExpandableLayout> 

    <!--other views--> 
</FrameLayout> 

설정 R.id.scrim. 그런 식으로 대화 상자로 찾고자하는 동작을 완벽하게 복제 할 수 있지만 성능은 훨씬 좋아집니다.