ExpandableLayout:Android 可扩展布局库,支持多种动画与灵活配置

[Deprecated] An android library that brings the expandable layout with various animation. You can include optional contents and use everywhere.

分支4Tags10
文件最后提交记录最后更新时间
10 年前
10 年前
9 年前
9 年前
9 年前
10 年前
10 年前
9 年前
10 年前
10 年前
9 年前
10 年前
10 年前
10 年前

可扩展布局

这是一个Android库,提供了带有多种动画效果的可扩展布局功能。 您可以添加可选内容,并在任意地方使用它。

  • Circle CI: 构建状态
  • Platform: 平台支持
  • Language: 编程语言
  • License: 许可证类型
  • Android Arsenal: Android资源库收录
  • Android Gems: Android宝石库

预览

正常模式

Expandable RelativeLayout Expandable Weight Layout

示例

Example RecyclerView Example Search Example Read More

使用方法

Expandable RelativeLayout

用途

当子视图大小可能会改变时,Expandable RelativeLayout可能无法正常工作。这种情况下,建议使用Expandable LinearLayout代替。

代码示例

ExpandableRelativeLayout expandableLayout = (ExpandableRelativeLayout) findViewById(R.id.expandableLayout);

// 切换展开和折叠状态
expandableLayout.toggle();
// 展开
expandableLayout.expand();
// 折叠
expandableLayout.collapse();

// 移动子视图位置
expandableLayout.moveChild(0);
// 移动到特定位置
expandableLayout.move(500);

// 设置闭合的基础位置
expandableLayout.setClosePosition(500);

布局XML

添加xmlns:app="http://schemas.android.com/apk/res-auto"

<com.github.aakira.expandablelayout.ExpandableRelativeLayout
    android:id="@+id/expandableLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:ael_expanded="false"
    app:ael_duration="500"
    app:ael_interpolator="bounce"
    app:ael_orientation="vertical">
    
    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="样本" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/text"
        android:text="样本2" />
</com.github.aakira.expandablelayout.ExpandableRelativeLayout>

Expandable LinearLayout

用途

如果子视图的大小可能会改变(例如,从服务器获取并设置值),应使用Expandable LinearLayout。特别适用于RecyclerView中。

代码示例

// 调整扩展布局大小

ExpandableLinearLayout expandableLayout = (ExpandableLinearLayout) findViewById(R.id.expandableLayout);

child.setText("从服务器设置文字");
expandableLayout.initLayout(); // 重新计算子视图的尺寸

// 在RecyclerView中的用法
// 必须设置ViewHolder#setIsRecyclable(false) 和 ExpandableLinearLayout#setInRecyclerView(true)

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    holder.setIsRecyclable(false);
    holder.expandableLinearLayout.setInRecyclerView(true);
}

Expandable Weight Layout

用途

如果您想在可扩展布局中使用权重属性,则应使用此布局。

代码示例

与之前类似,只是使用的布局是ExpandableWeightLayout,并且控制展开和关闭的方法相同。

布局XML示例

与Expandable RelativeLayout相似,但使用了ExpandableWeightLayout组件。

监听器

可以通过设置监听器来捕捉展开和折叠过程的关键事件。

expandableLayout.setListener(new ExpandableLayoutListener() {
    // 动画开始
    @Override
    public void onAnimationStart() { ... }
    // 动画结束
    @Override
    public void onAnimationEnd() { ... }
    // 扩展前调用
    @Override
    public void onPreOpen() { ... }
    // 折叠前调用
    @Override
    public void onPreClose() { ... }
    // 完全展开时
    @Override
    public void onOpened() { ... }
    // 完全折叠时
    @Override
    public void onClosed() { ... }
});

属性

属性名称 描述
ael_duration 展开或折叠动画的持续时间
ael_expanded 设置为true则布局处于展开状态
ael_defaultChildIndex 默认展开指定索引处的子视图(仅限Expandable RelativeLayout)
ael_defaultPosition 默认展开的位置(仅限Expandable RelativeLayout)
ael_orientation 动画的方向(水平 | 垂直)
ael_interpolator 设置插值器

插值器

可以使用插值器来定制动画效果。

支持多种插值器,如AccelerateDecelerateInterpolator, AccelerateInterpolator, BounceInterpolator等,每种都有对应的效果和属性值名称。

注意:某些插值器(如AnticipateInterpolator,AnticipateOvershootInterpolator,OvershootInterpolator)可能导致布局外扩展的表现不理想,在这些情况下,推荐用于扩展布局内的子视图动画。对于不支持的插值器(CycleInterpolator, PathInterpolator),则避免使用以确保正确行为。

设置

Gradle集成

在你的build.gradle文件中添加依赖项。

buildscript {
    repositories {
        jcenter()
    }
}

dependencies {
    implementation 'com.github.aakira:expandable-layout:1.6.0@aar'
}

作者

阿里卡·阿拉塔尼

其他开源项目

许可证

版权所有 © 2015 A.Akira

此软件采用Apache许可证2.0版("许可证")授权;
除非符合许可证的规定,否则不得使用此文件。
您可以在以下网址获得许可证副本:

http://www.apache.org/licenses/LICENSE-2.0

除非适用法律要求或书面同意,根据许可协议分发的软件
以"现状"基础提供,不附带任何明示或暗示的保证或条件。
请参阅许可证,了解具体的允许和限制规定。

[关联图片说明]:

项目介绍

【弃用】一款安卓库,它带来了带有多种动画的扩展布局功能。您可添加可选内容,并可在任何地方使用。【此简介由AI生成】

定制我的领域
511.65 K331访问 GitHub