gpt4 book ai didi

android - ExpandableLayout 动画不流畅

转载 作者:行者123 更新时间:2023-11-30 00:39:05 27 4
gpt4 key购买 nike

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

Click to screen shot

如上图所示,我使用 Utils.setWindowGravity(getWindow(), Gravity.BOTTOM); 将对话框放置在屏幕底部。如果我将其更改为 TOP,则动画有效 fine .但就我而言,我应该将其设置为底部。我该如何解决?

资源/布局:

<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);
}
}

最佳答案

我不认为这样改变对话框的大小是个好主意。根据我自己的经验,更改 Dialog 的高度非常低效,即使动画正常工作,也会非常卡顿。

我建议您将该界面实现为放置在整个 UI 上的自定义叠加层。

<?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 的点击监听器,以及当 expanderRatio 为零时隐藏整个叠加层的 ExpansionListener。这样您就可以完美地复制您正在寻找的对话框行为,而且性能要好得多。

关于android - ExpandableLayout 动画不流畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42852161/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com