aakira / expandablelayout Goto Github PK
View Code? Open in Web Editor NEW[Deprecated] An android library that brings the expandable layout with various animation. You can include optional contents and use everywhere.
License: Apache License 2.0
[Deprecated] An android library that brings the expandable layout with various animation. You can include optional contents and use everywhere.
License: Apache License 2.0
animation completed view visible shade in a existing layout not refreshing Exapndable RelativeLayout
i don't know how to compile compile 'com.github.aakira:expandable-layout:1.4.2@aar' into android studio Gradle
would u plz to tell me what should i have to do, also i am beginner in android
thanks
I tried to implement ExpandableLayout to my project, which resulted in following issue.
When I click the button to expand, I only get 1 line of text showing up (for a multi-line textview). This behaviour stays until I would rotate the device.
After rotation, everything works as expected.
I am using databinding, could have an effect? My impression is that the height of the relative layout is being calculated but not refreshed when new content arrives.
Hope this makes sense? Let me know if you need more info.
ExpandableRelativeLayout is work fine when I add view in xml. But it will expanded automatically when I add any view in java code. Anyway to still collapsed when I added any view?
First of all thanks for this nice libary and all the efford you put into it. 👍
I discovered an Issue with the measurement of the Layout size, when you put different childviews next to each other (with <android:layout_toRightOf="@id/someId">
)
It will measure the height as if all child views would be placed below from each other.
See example Layout
<de.desdroid.zauberkueche.ExpandableRelativeLayout
android:id="@+id/expand_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:ael_duration="500"
app:ael_expanded="false"
app:ael_interpolator="decelerate"
app:ael_orientation="vertical">
<ImageView
android:id="@+id/img_food"
android:layout_width="@dimen/img_width_food"
android:layout_height="@dimen/img_height_food"
android:scaleType="fitCenter"
android:src="@drawable/ic_cake" />
<Button
android:id="@+id/btn_gallery"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="@dimen/btn_width_add_photo"
android:layout_height="@dimen/btn_height_add_photo"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="@dimen/padding_48dp"
android:layout_marginLeft="@dimen/padding_8dp"
android:layout_marginRight="@dimen/padding_48dp"
android:layout_marginStart="@dimen/padding_8dp"
android:drawablePadding="@dimen/padding_8dp"
android:drawableTop="@drawable/ic_cake"
android:text="@string/btn_gallery" />
<Button
android:id="@+id/btn_photo"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="@dimen/btn_width_add_photo"
android:layout_height="@dimen/btn_height_add_photo"
android:layout_marginLeft="@dimen/padding_8dp"
android:layout_marginRight="@dimen/padding_8dp"
android:layout_toLeftOf="@id/btn_gallery"
android:layout_toStartOf="@id/btn_gallery"
android:drawablePadding="@dimen/padding_8dp"
android:drawableTop="@drawable/ic_cake"
android:text="@string/btn_photo" />
</de.desdroid.zauberkueche.ExpandableRelativeLayout>
I don't understand why you calculate the layout height on your own.
In your code of ExpandableRelativeLayout you call
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
So your parent class, which is RelativeLayout will already calculate height and width of the Layout.
You could then simply get Height and Width by
super.getMeasuredHeight();
// Or respectively for horizontal orientation
super.getMeasuredWidth();
When I set your local attribute layoutSize with the value retained by the super method, the bug is fixed.
Until this Bug is fixed, users can alternatively wrap their childs into one RelativeLayout and set it as the only child of ExpandableRelativeLayout.
I propose deleting the whole calculation block and using the super methods, for setting the layoutsize.
Or is there any reason why you have to calculate it on your own ? If so, please explain :)
I made the following hierarchy - RecyclerView with ExpandableLayout that has RecyclerView in itself and i just cant find a way to allow scrolling inside that nested recycler view, i tried with setNestedScrollingEnabled(true) but it won't help, can you help me with this if it is even possible to implement in this way? Thank you in advance :)
Both ExpandableLinearLayout and ExpandableRelativeLayout are incorrectly reporting their isExpanded() state after you expand, collapse and expand again. The layout always reports that it is expanded.
I got above mentioned error when I tried to build after adding this dependency in my build.gradle .
dependencies {
compile 'com.github.aakira:expandable-layout:1.4.0@aar'
}
ExpandableRelativeLayout not work app:ael_expanded = false in child fragment
version 1.5.1
to much issue in child fragemt
but it work in activity great
pls help
When scrolling a list with a lot of elements I expand one ExpandableLinearLayout then scroll again to another element where ExpandableLinearLayout is supposed to expand even more, but sadly it's reusing the same view and does not expand fully.
How can I force a new height calculation?
I have used a Expandable Linear Layout in recycler view and List view inside expandable layout but the list scroll isnt working and dynamic change of height has been a issue
How can I use this Layout with Custom Header as ListView's ListItem??
Here is my xml:
`
<com.github.aakira.expandablelayout.ExpandableLinearLayout
android:id="@+id/expandableLayout"
android:layout_width="match_parent"
android:layout_below="@+id/overlayText"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
app:ael_expanded="false"
app:ael_duration="300"
app:ael_interpolator="fastOutSlowIn"
app:ael_orientation="vertical">
<TextView
android:layout_width="match_parent"
android:minHeight="206dp"
android:layout_height="wrap_content"/>
</com.github.aakira.expandablelayout.ExpandableLinearLayout>
`
And this is my fragment code snippet:
`mExpandLayout = (ExpandableLinearLayout) root.findViewById(R.id.expandableLayout);
mOverlayText = (TextView) root.findViewById(R.id.overlayText);
mOverlayText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mExpandLayout.toggle();
}
});`
I should use ExpandableLinearLayout since the child will chage its size. Please, help!
ExpandableWeightLayout seems to only work if you have a view below with an equal weight. Without that 'balancing' view, the accelerator seems to expand to an infinite size (linearaccelerator accelerates quadratically, which becomes visible if you add a view below the expandablelayout with a weight of 0.01). If you're bound to have a 'balancing' view with the same weight, you can't have an expandablelayout filling the entire screen.
Hi there,
I like your library, but currently I am facing an issue.
I have some CardViews, each one containing an ExpandableRelativeLayout.
In CardView 1 there is a RadioGroup which manipulates the visibility of some Views in CardView 3 to VISIBLE or GONE.
But the height of CardView 3 is too large after some Views are GONE.
Using some requestLayout() calls won't help.
Somehow the new height must be measured.
Do you know a function for this?
I am sorry NOT to send some code...
Placing a second ExpandableRelativeLayout into the first one causes a similiar problem. The inner one does not expand or collapse correctly, becourse the height of the outside container does not change.
Best regards,
DaRolla
how to add this library to android studio 1.3??
I have markup which looks like:
<com.github.aakira.expandablelayout.ExpandableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--<TextView xmlns:android="http://schemas.android.com/apk/res/android"-->
<!--android:id="@+id/tv7778"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="@dimen/input_height"-->
<!--android:background="@drawable/border11_bottom"-->
<!--android:gravity="center_vertical"-->
<!--android:text="WE NEVER FORGET WE NEVER FORGIVE"/>-->
</com.github.aakira.expandablelayout.ExpandableLinearLayout>
and if I comment textview in the middle it's fails with:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.test PID: 3618
java.lang.ArrayIndexOutOfBoundsException: length=0; index=-1
at java.util.ArrayList.get(ArrayList.java:310)
at com.github.aakira.expandablelayout.ExpandableLinearLayout.onMeasure(ExpandableLinearLayout.java:126)
at android.view.View.measure(View.java:18788)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:18788)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
at android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
at android.view.View.measure(View.java:18788)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
The library is working fine in my fragment setting the XML attribute to app:ael_expanded="false"
and toggling it from the fragment class, however I want in some situations to overcome the XML attribute and make it start expanded not collapsed. I tried expandedLayout.expand()
and expandedLayout.setExpanded(true)
however they are not working and even disabling the normal toggle() function. How can I do that ?
Please note I tried the above methods in different methods of the fragment lifecycle with no result.
I think it has to do with the onMeasure calculations not being correct after rotation.
If anyone else has this issue, I switched to using https://github.com/cachapa/ExpandableLayout instead, similar functionality and works fine on rotation.
TextView does not correctly calculate its size being in ExpandableLinearLayout with a vertical orientation and . android:layout_height="wrap content"android:layout_marginLeft="32dp") it ignores the indentation. To solve this problem, I changed a bit the code onMeasure (...
view = getChildAt(i);
params = (LayoutParams) view.getLayoutParams();
view.measure(MeasureSpec.makeMeasureSpec(view.getMeasuredWidth()- params.leftMargin - params.rightMargin, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
.... ).
And replaced to account for the opening.
if (!defaultExpanded) {
setLayoutSize(closePosition);
to
setLayoutSize(
(isExpanded()
?layoutSize
:closePosition)
);
May still have to add a check for horizontal orientation. While nothing to check.
Hello, thank you for the great library. I use "Expandable Layout" in my application, and sometimes I get the stacktrace:
Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: length=65; index=-1
at android.text.StaticLayout.calculateEllipsis(StaticLayout.java:731)
at android.text.StaticLayout.out(StaticLayout.java:643)
at android.text.StaticLayout.generate(StaticLayout.java:427)
at android.text.StaticLayout.(StaticLayout.java:144)
at android.widget.TextView.makeSingleLayout(TextView.java:6471)
at android.widget.TextView.makeNewLayout(TextView.java:6328)
at android.widget.TextView.onMeasure(TextView.java:6704)
at android.view.View.measure(View.java:17525)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1263)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:615)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1083)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:615)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at com.github.aakira.expandablelayout.ExpandableLinearLayout.onMeasure(SourceFile:109)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17525)
at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1263)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.widget.ScrollView.onMeasure(ScrollView.java:337)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17525)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:728)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:464)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(SourceFile:700)
at android.support.design.widget.CoordinatorLayout.onMeasure(SourceFile:767)
at android.view.View.measure(View.java:17525)
at android.support.v4.widget.DrawerLayout.onMeasure(SourceFile:1081)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.support.v7.widget.ContentFrameLayout.onMeasure(SourceFile:135)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17525)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5464)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2564)
at android.view.View.measure(View.java:17525)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2022)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1175)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1393)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1063)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5807)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5319)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1016)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)
I could not understand how to use. I looked examples but I did not understand what is doing here.
Its a strange behaviour, when ever activity goes in background and we try to recreate it, it crashes with following error Unmarshalling unknown type code 37 at offset 724.
After removing ExpandableRelativelayout it works ok.
When inflating the layout from a Fragment, the ExpandableRelativeLayout auto expands even if the app:ael_expanded is set to false. I've checked the value of isExpanded inside onCreateView function and it returns false. This is the strange thing actually, when the keyboard opens the ExpandableRelativeLayout collapses.
My ExpandableRelativeLayout contains EditText and yes the EditTexts are not focused. First I thought, the EditTexts are focusing automatically, that's why this is happening. I disabled the EditText focus, but the result is still the same.
I want to use this library in my app but I'm facing some issues with it. I have a ViewPager
with 3 Tabs, first 2 are displaying some images and the last one has a RecyclerView
displaying 5 Card Views
. Once expanded, each Card
will display 3 paragraphs, except the last Card
which has only 1 paragraph and it's the one that's bodering me because it expands too much . I recorded a bit so you can make an idea of what's going on. Also the second Card
is showing only 1 paragraph instead of 3, but not always... Sorry for my english and thanks a lot for this library!
The video: https://vid.me/HGTv
Last tab from the ViewPager
:
public class Tab3 extends Fragment {
public Tab3 () {
// Required empty public constructor
}
public Tab3 newInstance() {
return new Tab3 ();
}
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.tab_3, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity()));
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
final List<DataTab3> data = new ArrayList<>();
data.add(new DataTab3(
"CardView no.1",
Utils.createInterpolator(Utils.FAST_OUT_LINEAR_IN_INTERPOLATOR)));
data.add(new DataTab3(
"CardView no.2",
Utils.createInterpolator(Utils.FAST_OUT_LINEAR_IN_INTERPOLATOR)));
data.add(new DataTab3(
"CardView no.3",
Utils.createInterpolator(Utils.FAST_OUT_LINEAR_IN_INTERPOLATOR)));
data.add(new DataTab3(
"CardView no.4",
Utils.createInterpolator(Utils.FAST_OUT_LINEAR_IN_INTERPOLATOR)));
data.add(new DataTab3(
"CardView no.5",
Utils.createInterpolator(Utils.FAST_OUT_LINEAR_IN_INTERPOLATOR)));
recyclerView.setAdapter(new NewAdapter(data));
}
}
The Adapter:
public class NewAdapter extends RecyclerView.Adapter<NewAdapter.ViewHolder> {
private final List<DataTab3> data;
private Context context;
private SparseBooleanArray expandState = new SparseBooleanArray();
public NewAdapter(final List<DataTab3> data) {
this.data = data;
for (int i = 0; i < data.size(); i++) {
expandState.append(i, false);
}
}
@Override
public ViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) {
this.context = parent.getContext();
return new ViewHolder(LayoutInflater.from(context)
.inflate(R.layout.tab_3_adapter, parent, false));
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
final DataTab31 item = data.get(position);
holder.SecondTextView.setText(DataTab3.Tab3Content[position]);
holder.textView.setText(item.description);
holder.expandableLayout.setInterpolator(item.interpolator);
holder.expandableLayout.setExpanded(expandState.get(position));
holder.expandableLayout.setListener(new ExpandableLayoutListenerAdapter() {
@Override
public void onPreOpen() {
createRotateAnimator(holder.buttonLayout, 0f, 180f).start();
expandState.put(position, true);
}
@Override
public void onPreClose() {
createRotateAnimator(holder.buttonLayout, 180f, 0f).start();
expandState.put(position, false);
}
});
holder.buttonLayout.setRotation(expandState.get(position) ? 180f : 0f);
holder.buttonLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
onClickButton(holder.expandableLayout);
}
});
}
private void onClickButton(final ExpandableLayout expandableLayout) {
expandableLayout.toggle();
}
@Override
public int getItemCount() {
return data.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView textView;
public TextView SecondTextView;
public RelativeLayout buttonLayout;
public ExpandableRelativeLayout expandableLayout;
public ViewHolder(View v) {
super(v);
SecondTextView = (TextView) v.findViewById(R.id.secondTextView);
textView = (TextView) v.findViewById(R.id.textView);
buttonLayout = (RelativeLayout) v.findViewById(R.id.button);
expandableLayout = (ExpandableRelativeLayout) v.findViewById(R.id.expandableLayout);
}
}
public ObjectAnimator createRotateAnimator(final View target, final float from, final float to) {
ObjectAnimator animator = ObjectAnimator.ofFloat(target, "rotation", from, to);
animator.setDuration(300);
animator.setInterpolator(Utils.createInterpolator(Utils.LINEAR_INTERPOLATOR));
return animator;
}
}
ItemModel:
public class ItemModel {
public final String description;
public final TimeInterpolator interpolator;
public ItemModel(String description, TimeInterpolator interpolator) {
this.description = description;
this.interpolator = interpolator;
}
public static final String[] Tab3Content = {
"• This is a simple example, no1\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.\n" +
"\n" +
"• Sample.sample.Sample.sample.\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample." +
"\n" +
"• Sample.sample.Sample.sample.\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.",
"• This is a simple example, no2\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.\n" +
"\n" +
"• Sample.sample.Sample.sample.\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample." +
"\n" +
"• Sample.sample.Sample.sample.\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.",
"• This is a simple example, no3\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.\n" +
"\n" +
"• Sample.sample.Sample.sample.\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample." +
"\n" +
"• Sample.sample.Sample.sample.\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.",
"• This is a simple example, no4\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.\n" +
"\n" +
"• Sample.sample.Sample.sample.\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample." +
"\n" +
"• Sample.sample.Sample.sample.\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.",
"• This is a simple example, no5\n" +
" Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.Sample.sample.",
};
}
The adapter's layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@color/md_white_1000"
app:cardElevation="5dp">
<RelativeLayout 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="wrap_content">
<RelativeLayout
android:id="@+id/button"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:gravity="center">
<View
android:layout_width="12dp"
android:layout_height="12dp"
android:background="@drawable/triangle" />
</RelativeLayout>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@id/button"
android:layout_toStartOf="@+id/button"
android:padding="8dp"
android:textColor="@color/green_teal"
android:textSize="18sp" />
<com.github.aakira.expandablelayout.ExpandableRelativeLayout
android:id="@+id/expandableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/textView"
android:background="@color/md_white_1000"
app:ael_expanded="false"
app:ael_duration="400"
app:ael_orientation="vertical">
<TextView
android:id="@+id/secondTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textColor="@color/md_grey_900"
android:textSize="18sp" />
</com.github.aakira.expandablelayout.ExpandableRelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
When I scroll a RecyclerView, and use the method 'setExpand(boolean)' in onBindViewHolder().
The expand or collapse state isn't right.
PS: All boolean data in a SparseBooleanArray, datas are correct. And it isn't a convert question.
In case of more than one ExpandableRelativeLayout in the xml file, only the first one will work properly. The second one won't respond to toggle functions.
In my actual project I was using two expandable layouts, each containing a recyclerview, and the problem was even worse.
As you can see, the first item of recycleview is recycled when i scroll down to the buttom.
So the last item is epanded as the first one.
When i collapse the last one, the first one collapse too.
In fact, they are the same one.
I meet this problem many times and i can't find way to deal with it.
Do you have any idea? Although it's no matter about your library.
Thanks in advance.
Hi, I have been trying to have a button pressed, which will expand vertically a layout showing a horizontal RecyclerView. Also, the items of the RecyclerView to have gravity right.
I have tried ExpandableRelativeLayout, ExpandableLinearLayout and ExpandableWeightLayout, with different configurations, but nothing seems to work.
Examples of problems encountered:
Layout expanding but list not showing, layout always expanded/toggle button does nothing, layout expanding but to a smaller size than that of the list, etc.
You have examples of a RecyclerView that includes ExpandableLayout. Is the opposite possible?
Thanks.
Example layout:
<com.github.aakira.expandablelayout.ExpandableRelativeLayout
android:id="@+id/expandable_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/show_button"
app:ael_duration="700"
app:ael_expanded="false"
app:ael_interpolator="bounce"
app:ael_orientation="horizontal">
<android.support.v7.widget.RecyclerView
android:id="@+id/expandable_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</android.support.v7.widget.RecyclerView>
</com.github.aakira.expandablelayout.ExpandableRelativeLayout>
You should use the ExpandableLinearLayout if child views may change a size.
For example, it gets and sets values after connection.
The ExpandableRelativeLayout isn't supported in the above.
child.setText("Sets text from a server");
expandableLayout.initLayout(true);``// Recalculate size of children
initLayout()
is deprecated in v1.5.0.
The argument of isMaintain
doesn't work.
Hi AAkira! Thanks for this lib. It helps me a lot.
I put recyclerView inside ExpandableLayout.
But it gets gone after I toggle ExpandableLayout and never become visible. Can you give tips about how to handle it, please?
Why I went with this way? Before, I put Viewpager with Fragments inside ExpandableLayout, and each Fragment contains Recyclerview. And it works well.
A LinearLayout variant would be useful
Hi,
I'm using the ExpansiveLinearLayout and I'm setting the adapter in the onResume method of my activity. All items are collapsed but when I return to this activity all items are expanded. Is there any problem related to setting the adapter for the ExpandableLinearLayout in the onResume method?
Following my code:
activity_items.xml
<com.github.aakira.expandablelayout.ExpandableLinearLayout
android:id="@+id/list_item_car_expandable_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:ael_duration="400"
app:ael_expanded="false">
<TextView
android:id="@+id/list_item_car_expandable_layout_information"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="8dp"
android:visibility="visible"
android:weightSum="2">
</LinearLayout>
</com.github.aakira.expandablelayout.ExpandableLinearLayout>
CustomAdapter.java
private final List<Item> mItems;
private Context mContext;
private SparseBooleanArray mExpandState = new SparseBooleanArray();
public static class ItemView extends RecyclerView.ViewHolder {
TextView textDisplayName;
TextView textInformation;
ExpandableLinearLayout expandableLayout;
View buttonLayout;
public ItemView(View view) {
super(view);
textDisplayName = (TextView) view.findViewById(R.id.list_item_car_display_name);
textInformation = (TextView) view.findViewById(R.id.list_item_car_expandable_layout_information);
expandableLayout = (ExpandableLinearLayout) view.findViewById(R.id.list_item_car_expandable_layout);
buttonLayout = view.findViewById(R.id.list_item_car_expand_button);
}
}
public CustomAdapter(final List<Item> aItems) {
this.mItems = aItems;
for (int i = 0; i < mItems.size(); i++) {
mExpandState.append(i, false);
}
}
@Override
public ItemView onCreateViewHolder(final ViewGroup parent, final int viewType) {
this.mContext = parent.getContext();
return new ItemView(LayoutInflater.from(mContext).inflate(R.layout.list_item_custom, parent, false));
}
private void onClickButton(final ExpandableLinearLayout expandableLayout) {
expandableLayout.toggle();
}
@Override
public void onBindViewHolder(final ItemView holder, final int position) {
final Item item = mItems.get(position);
holder.setIsRecyclable(true);
holder.textDisplayName.setText(item.getDisplayName());
holder.textDisplayName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onClickButton(holder.expandableLayout);
}
});
holder.expandableLayout.setInRecyclerView(true);
holder.expandableLayout.setExpanded(mExpandState.get(position));
holder.expandableLayout.setListener(new ExpandableLayoutListenerAdapter() {
@Override
public void onPreOpen() {
createRotateAnimator(holder.buttonLayout, 0f, 180f).start();
mExpandState.put(position, true);
}
@Override
public void onPreClose() {
createRotateAnimator(holder.buttonLayout, 180f, 0f).start();
mExpandState.put(position, false);
}
});
holder.buttonLayout.setRotation(mExpandState.get(position) ? 180f : 0f);
holder.buttonLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
onClickButton(holder.expandableLayout);
}
});
holder.textInformation.setText(tem.getInformation());
}
@Override
public int getItemCount() {
return mItems.size();
}
public ObjectAnimator createRotateAnimator(final View target, final float from, final float to) {
ObjectAnimator animator = ObjectAnimator.ofFloat(target, "rotation", from, to);
animator.setDuration(300);return animator;
}
MyActivity.java
public class MyActivity extends AppCompatActivity {
@ViewById(R.id.activity_cars_recycler_view)
protected RecyclerView mRecyclerView;
@Override
protected void onCreate(Bundle savedInstance){
super.onCreate(savedInstance);
setContentView(R.layout.activity_items);
mRecyclerView = (RecyclerView) findViewById(R.id.activity_recycler_view);
}
@Override
public void onResume(){
super.onResume();
loadItems();
}
private void loadItems(){
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
List<Item> items = CustomController.getInstance.getAllItems();;
mRecyclerViewsetAdapter(new CustomAdapter(items));
}
}
Thanks in advance,
Vinicius Lafourcade
Hi!
I am trying to bind an ExpandableLinearLayout to my ViewModel, but I get the following error:
Error:(193, 33) Cannot find the setter for attribute 'app:ael_expanded' with parameter type boolean on com.github.aakira.expandablelayout.ExpandableLinearLayout.
My layout is this:
...
<com.github.aakira.expandablelayout.ExpandableLinearLayout
android:id="@+id/layout_expandable_linear_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/button_expandable_toggle"
android:orientation="vertical"
app:ael_duration="500"
app:ael_expanded="@{viewModel.expandedCheckboxes}"
app:ael_interpolator="bounce">
...
</com.github.aakira.expandablelayout.ExpandableLinearLayout>
Any idea why this should not work?
As far as I can see, there is a setExpanded(boolean)
function in ExpandableLinearLayout.java
but maybe it cannot see that ael_expanded
should map to that function?
I am using like this,
<com.github.aakira.expandablelayout.ExpandableRelativeLayout
android:id="@+id/expandableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/header"
android:background="@drawable/recycler_item_bg"
app:ael_duration="400"
app:ael_expanded="true"
app:ael_orientation="vertical"
>
<ListView
android:id="@+id/lv_routes_assigned"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="@color/fontColor"
android:textSize="16sp"
/>
</com.github.aakira.expandablelayout.ExpandableRelativeLayout>
What can be done to remove that extra space below of listview.
ExpandableLinearLayout does not work after adding view programatically
If Programatically we would call :
getLayoutInflater().inflate(R.layout.partial, expandable, true);
then Expanding will not work properly.
If using expandable.initLayout(true);
then there are 2 cases:
getMeasuredHeight() == 0
If not using expandable.initLayout(true);
then last item is also not visible. (due the isCalculatedSize == true
)
ExpandableRelativeLayout is wrap_content, and it hold a LinearLayout as child element.
When LinearLayout's height change, ExpandableRelativeLayout doesn't change.
I try initLayout, requestLayout, invalidate.
Doesn't work.
Hello Friends,
I want to expand only one child at a time, I mean Show only one child of Expandable Layout list at a time android.
so please can you tell me , How do it's work.?
I mean which property is used for that.?
Hi! I'm including your lib to a personal android app and I've found this problem when Android Studio finished to sync the project. I don't know how to fix it, so I open this issue thinking that someone could help me.
Thanks for all your work :)
ListView is not scrolling inside recycler view.
holder.expandableLayout.setInRecyclerView(true);
holder.setIsRecyclable(true);
Not scrolling
I have an animation inside the expandable layout. Once the animation is complete, it stays that size and pushes the textview (also in the expandable layout below). All this works fine, but the textview is not completely displayed. You can notice the top of the line of text (that is not displayed properly) in the image
Here is the code. I have used the method used in readmoreexpandablelayout example:
` playImageView = (ImageView) findViewById(R.id.scale_anim);
elIV = (ExpandableRelativeLayout) findViewById(R.id.rarticle_el_iv);
final ImageView ivPlay = (ImageView) findViewById(R.id.scale_play);
globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
elIV.move(playImageView.getHeight(), 0, null);
playImageView.getViewTreeObserver().removeOnGlobalLayoutListener(globalLayoutListener);
}
};
playImageView.getViewTreeObserver().addOnGlobalLayoutListener(globalLayoutListener);
playImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ImageAnimation ia = new ImageAnimation(ivPlay, ivPlay.getWidth(), (int) (1.25 * ivPlay.getWidth()), ivPlay.getHeight(), (int) (2 * ivPlay.getHeight()));
ia.setDuration(2000);
ia.setFillEnabled(true);
ia.setFillAfter(true);
ivPlay.startAnimation(ia);
playImageView.setVisibility(View.GONE);
elIV.expand(10000, new FastOutSlowInInterpolator());
}
});
}`
This is the relevant xml code:
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/scale_anim"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/play" />
<com.github.aakira.expandablelayout.ExpandableRelativeLayout
android:id="@+id/rarticle_el_iv"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/scale_play"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="@drawable/play" />
<TextView
android:id="@+id/rarticle_tv_article_iv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/scale_play"
android:text="There is an idea which generally people or in particular, the quacks have. They impart spirituality without any consideration of the receiver’s capacity. Even when the disciple is full of darkness, they start infusing Divine effulgence into him. The disciple, no doubt, improves by the force they impart, but the already existing darkness also goes on developing. If you add power to an object, its own ingredients will also develop. If the process is continued, the darkness swells and goes on becoming more and more solid. On the contrary, if the correct method is followed, and the darkness removed first, very good results will be obtained." />
</com.github.aakira.expandablelayout.ExpandableRelativeLayout>
</RelativeLayout>
Here's what I found:
The total height that the ExpandableLayout expands is 1080 px = width of my phone = max height of the imageView can be while maintaining aspect ratio
Seems like there is an issue with nested expandable layouts. I have two ExpandableLinearLayout
. One ExpandableLinearLayout
nested into RelativeLayout
and nested into another ExpandableLinearLayout
with vertical orientation. I also have buttons to control layouts expanding/collapsing. Here is markup:
<com.github.aakira.expandablelayout.ExpandableLinearLayout
android:id="@+id/outer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/inner_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Toggle inner"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.github.aakira.expandablelayout.ExpandableLinearLayout
android:id="@+id/inner_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/colorAccent"
android:text="Nested"/>
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/colorPrimary"
android:text="Nested 2"/>
</com.github.aakira.expandablelayout.ExpandableLinearLayout>
</RelativeLayout>
</com.github.aakira.expandablelayout.ExpandableLinearLayout>
<Button
android:id="@+id/outer_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Toggle outer"/>
So, the problem in nested ExpandableLinearLayout
. When I try to expand/collapse it nothing happens. I've created demo project.
It's a critical issue for me. Any ideas it can be resolved?
Hi,
TnQ for this great library.
Can u pllz add cardView expandable?
This propriety would control if the expandablelayout is open or close only on android studio's preview similar to textview's tools:text.
Can you provide an example of nesting ExpandableLayout?
I'm not sure if this is possible with the current implementation of ExpandableRelativeLayout.
TextInputEditText inputEdittext = ButterKnife.findById(view, R.id.input_edittext);
inputEdittext.addTextChangedListener(this);
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
mExpandableLayout.initLayout(true);
}
<com.github.aakira.expandablelayout.ExpandableLinearLayout
android:id="@+id/expandable_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:ael_expanded="false"
app:ael_duration="@integer/expand_note_duration"
app:ael_interpolator="anticipateOvershoot"
app:ael_orientation="vertical">
<android.support.design.widget.TextInputLayout
android:id="@+id/input_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColorHint="@color/section_name_color">
<android.support.design.widget.TextInputEditText
android:id="@+id/input_edittext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minLines="4"
android:hint="@string/dialog_title_note"
android:textSize="@dimen/detail_text_size"
android:inputType="textMultiLine|textLongMessage"
android:textColor="@color/speaker_color"
android:textColorHint="@color/section_name_color" />
</android.support.design.widget.TextInputLayout>
</com.github.aakira.expandablelayout.ExpandableLinearLayout>
Hello everyone,
I have small problem with expandable relative layout. In my layout I using linear layout inside expandable relative layout and I programmatically add textview on this linear layout. This method work ok in onCreate() method but when i waiting data from server and after receiving data i trying add view to linear layout inside expandable layout, nothing happens. Does anyone know where is the problem?
Code is below:
` <com.github.aakira.expandablelayout.ExpandableRelativeLayout
android:id="@+id/expandableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:ael_expanded="false"
app:ael_duration="300"
app:ael_interpolator="fastOutLinearIn"
app:ael_orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fee_container"
android:orientation="vertical"
/>
</com.github.aakira.expandablelayout.ExpandableRelativeLayout>`
and java code:
` for (int i = 0; i < 3; i++) {
View layout = LayoutInflater.from(getApplicationContext())
.inflate(R.layout.fee_item, mFeeContainer, false);
TextView mPrice = (TextView) layout.findViewById(R.id.price);
TextView mType = (TextView) layout.findViewById(R.id.type);
mPrice.setText("price" + i);
mType.setText("type" + i);
mFeeContainer.addView(layout);
}`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.