2017-03-17 135 views
1

我在对话框布局中使用cachapa/ExpandableLayout,但我遇到了一些意想不到的动画。我的意思是,可扩展的布局不会平稳移动,而是突然移动。ExpandableLayout动画不平滑

Click to screen shot

正如你可以看到上面的图片,我把对话在使用Utils.setWindowGravity(getWindow(), Gravity.BOTTOM);屏幕的底部。如果我将其更改为TOP,则动画的作品fine。但就我而言,我应该把它设置在底部。我该如何解决它?

RES /布局:

<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> 

的Java

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

我不认为这是一个好主意,会改变你的对话框的大小类似。根据我自己的经验,改变对话框的高度是非常困难的,即使动画运行正常,它也会非常令人难以置信。

我建议您将该接口作为您放置在整个用户界面上的自定义覆盖图来实现。

<?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为关闭您的ExpandableLayout点击监听器和隐藏整个覆盖时expansionRatio是零ExpansionListener。 通过这种方式,您可以完美地复制使用对话框查找的行为,但性能更好。