ExpandableLayout

介绍:

可扩展布局,各种动画效果。

运行效果:

使用说明:

 ExpandableRelativeLayout

代码

ExpandableRelativeLayout expandLayout
 = (ExpandableRelativeLayout) findViewById(R.id.expandableLayout);
// toggle expand, collapse
expandableLayout.toggle();
// expand
expandableLayout.expand();
// collapse
expandableLayout.collapse();
// move position of child view
expandableLayout.moveChild(0);
// move optional position
expandableLayout.move(500);
// set base position which is close position
expandableLayout.setClosePosition(500);

Layout 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:defaultVisibility="false"
    app:duration="500"
    app:interpolator="bounce"
    app:orientation="vertical">
    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="sample" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/text"
        android:text="sample2" />
</com.github.aakira.expandablelayout.ExpandableRelativeLayout>

ExpandableWeightLayout

如果你想在expandable布局中使用weight属性,你应该使用这个布局。

代码

ExpandableWeightLayout expandLayout
 = (ExpandableWeightLayout) findViewById(R.id.expandableLayout);
// toggle expand, collapse
expandableLayout.toggle();
// expand
expandableLayout.expand();
// collapse
expandableLayout.collapse();

Layout xml

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

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>
    <com.github.aakira.expandablelayout.ExpandableWeightLayout
        android:id="@+id/expandableLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        app:duration="1000"
        app:interpolator="anticipateOvershoot">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/sample" />
    </com.github.aakira.expandablelayout.ExpandableWeightLayout>
    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"/>
</LinearLayout>

Listener

expandableLayout.setListener(new ExpandableLayoutListener() {
    @Override
    public void onAnimationStart() {
    }
    @Override
    public void onAnimationEnd() {
    }
    @Override
    public void onOpened() {
    }
    @Override
    public void onClosed() {
    }
});

属性

attribute namedescription
durationThe length of the expand or collapse animation
defaultVisibilityThe layout is expanded at first if you set true
orientationThe orientation of animation(horizontal
interpolatorSets interpolator

Interpolator

你可以使用 interpolator来让布局动画更容易。

Interpolatorvalue name of attribute
AccelerateDecelerateInterpolatoraccelerateDecelerateInterpolator
AccelerateInterpolatoraccelerateInterpolator
AnticipateInterpolatoranticipateInterpolator
AnticipateOvershootInterpolatoranticipateOvershootInterpolator
BounceInterpolatorbounceInterpolator
DecelerateInterpolatordecelerateInterpolator
FastOutLinearInInterpolatorfastOutLinearInInterpolator
FastOutSlowInInterpolatorfastOutSlowInInterpolator
LinearInterpolatorlinearInterpolator
LinearOutSlowInInterpolatorlinearOutSlowInInterpolator
OvershootInterpolatorovershootInterpolator

These are support interpolator. But a case that the expandable layout extends outside doesn't work. e.g. AnticipateInterpolator, AnticipateOvershootInterpolator, OvershootInterpolator I recommend you use such a interpolator for child views in the expandable layout.

  • 不支持

  • CycleInterpolator

  • PathInterpolator

设置

Gradle

在build.gradle中添加如下依赖:

buildscript {
    repositories {
        jcenter()
    }
}
dependencies {
    compile 'com.github.aakira:expandable-layout:1.0.0@aar'
}
已下载
0