cachapa / expandablelayout Goto Github PK
View Code? Open in Web Editor NEWAn expandable layout container for Android
License: Apache License 2.0
An expandable layout container for Android
License: Apache License 2.0
Hi,
Kindly help me out for this situation.
I'm having recyclerview and on view click I used your library for expand and collapse. Issue here is expandableview layout has been created dynamically based on the API response. So on the time of API loading if I scroll the layout then the view not updated with the records from API.
I guess onBindView will get called on scroll and view got refreshed. But I'm not sure how to load childview data when scrolled.
I inserted "notifiyItemChanged" in OnBindHolder but it throws exception layout can be refreshed on scroll Illegal state exception. Kindly share your thoughts.
It will auto collapse when the expandable layout is RecyclerView and it's WRAP_CONTENT, I have to add a parent layout to the RecyclerView and set minHeight to make sure the RecyclerView is visible.
After recycling state of view is change from expanded to collapsed.
if item click in recycler view then selected item show properly not hide at bottom or not hide top on screen.
how to solve
If answer is yes. pls tell me how?
I just noticed that if i scroll to the last item and click to expand, then part of the opened view is invisible. How can i scroll down to make the whole view visible?
If I understand correctly, these methods should expand/collapse view instantly without animation, but they do nothing.
I have expandable view in recycler. I fill it (it contains LinearLayout) with additional views in adapter.
Expanding/Collapse works correctly when there is animation, but if there is no animation nothing happens.
Please advise.
I need to animate the layout bottom up. Can I do this with the current version? Please help, thanks.
There is a collision with the attribute orientation when using this lib with others that also define an attribute "orientation". This would be fixed by renaming "orientation" into "el_orientation"
It would be really helpful to support a collapsed layout as well for situations where you want to show some content, then expand to show more. In my case the description of an article.
the expanded item will collapse again when visible
When using the library with a RecycleView, at startup and whenever you update your adapter, it will automatically scroll to the bottom of the recycleview.
Not a big deal, you just have to add the check of the state in the RecyclerViewFragment to prevent it.
@Override
public void onExpansionUpdate(float expansionFraction, int state) {
if(state!=ExpandableLayout.State.COLLAPSED)
recyclerView.smoothScrollToPosition(getAdapterPosition());
}
Actually this is not really an issue, but I think this can prevent some unexpected behaviour and still be consistent to the general case.
I'm using RecyclerView. When I click on an Item the content (Relative Layout) is expanded well. To collapse this expanded content I have to click on Item.
Is it possible to collapse the expanded content after clicking on it (in my case click on a Relative Layout).
Thank you for making this awesome library. <3
I was trying to emulate a semi collapsed/expanded view - similar to how Google Play Store uses READ MORE / READ LESS for its app descriptions page.
I set it up so that the expansion level is set to 20% using the setExpansion()
method. However, the state change is rather abrupt. I realize this is intended behavior but is there a way to pass an expansion level and it smoothly expands/collapses to that point?
Is there any way i can add a callback to the expand call..
I am using Bounce Interpolator with the Expandable layout but when i expand i need to click at least two time for it close again. If i don't use any interpolator everything works like it should.
if (details.isExpanded()) {
details.collapse();
vPrecoComum.animate().alpha(1).start();
details.animate().alpha(0).setDuration(300).start();
expandButton.animate().rotation(0).start();
} else {
details.expand();
vPrecoComum.animate().alpha(0).start();
details.animate().alpha(1).setDuration(300).start();
expandButton.animate().rotation(180).start();
}
I tried debugging it end i saw that the expansion value is 1.0000545 on the first click.
The first time I expand an item, I don't get onClicked event, only after I expand/collapse a second time and I don't know why.
Here's my code :
`public class RestaurantAdapter extends RecyclerView.Adapter<RestaurantAdapter.ViewHolder>{
private static final int UNSELECTED = -1;
private List restaurantList;
private static int selectedItem = UNSELECTED;
private RecyclerView recyclerView;
private Context context;
//constructor, call on creation
public RestaurantAdapter(ArrayList<Restaurant> restaurantList, RecyclerView recyclerView, Context context) {
this.restaurantList = restaurantList;
this.recyclerView = recyclerView;
this.context = context;
}
// Create new views (invoked by the layout manager)
@Override
public RestaurantAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
// create a new view
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_item_layout, parent, false);
// set the view's size, margins, paddings and layout parameters
Log.w("RestaurantAdapter", "View created");
ViewHolder vh = new ViewHolder(v);
return vh;
}
@Override
public void onBindViewHolder(RestaurantAdapter.ViewHolder holder, int position) {
Restaurant restaurant = restaurantList.get(position);
holder.name.setText(restaurant.getName());
holder.distance.setText(restaurant.getDistance() + " m");
Log.w("RestaurantAdapter", "Data binded");
holder.bind();
}
@Override
public int getItemCount() {
return restaurantList.size();
}
public List<Restaurant> getRestaurantList() {
return restaurantList;
}
public void setRestaurantList(List<Restaurant> restaurantList) {
this.restaurantList = restaurantList;
}
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, ExpandableLayout.OnExpansionUpdateListener{
// each data item is just a string in this case
private TextView name, distance;
private Button details;
private ExpandableLayout expandableLayout;
private LinearLayout layoutTextView;
private ViewHolder holder;
private ViewHolder(View v) {
super(v);
name = (TextView) v.findViewById(R.id.listTitle);
distance = (TextView) v.findViewById(R.id.listDistance);
expandableLayout = v.findViewById(R.id.expandable_layout);
layoutTextView = v.findViewById(R.id.layoutTextView);
details = (Button) v.findViewById(R.id.details);
expandableLayout.setInterpolator(new OvershootInterpolator());
expandableLayout.setOnExpansionUpdateListener(this);
layoutTextView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Log.w("RestaurantAdapter", "View clicked");
final ViewHolder holder = (ViewHolder) recyclerView.findViewHolderForAdapterPosition(selectedItem);
if(holder != null) {
holder.details.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(context, RestaurantActivity.class);
Toast.makeText(context, "Activity Launched", Toast.LENGTH_SHORT).show();
holder.layoutTextView.setSelected(false);
holder.expandableLayout.collapse();
}
});
holder.layoutTextView.setSelected(false);
holder.expandableLayout.collapse();
}
int position = getAdapterPosition();
if (position == selectedItem) {
selectedItem = UNSELECTED;
} else {
layoutTextView.setSelected(true);
expandableLayout.expand();
selectedItem = position;
}
}
@Override
public void onExpansionUpdate(float expansionFraction, int state) {
Log.d("ExpandableLayout", "State: " + state);
if (state == ExpandableLayout.State.EXPANDING) {
recyclerView.smoothScrollToPosition(getAdapterPosition());
}
}
private void bind() {
int position = getAdapterPosition();
boolean isSelected = position == selectedItem;
layoutTextView.setSelected(isSelected);
expandableLayout.setExpanded(isSelected, false);
}
}
}
`
issue : on Item click it open at bottm of all item in recyclerview
expected result it should open bottom of clicked item.
This propriety would control if the expandablelayout is open or close only on android studio's preview similar to textview's tools:text.
Hi,
When i use ExpandableLayout with RecyclerView, the Android doesn't allow to inflate class.
The error report:
"FATAL EXCEPTION: main android.view.InflateException: Binary XML file line #38: Error inflating class net.cachapa.expandablelayout.ExpandableLayout"
And points to the following line of my code:
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.expandable_minha_consulta_row, parent, false);
Hello,
I am using a vertical RecyclerView and in every item of this RecyclerView I have a horizontal RecyclerView. What I'm trying to achieve is when I click on an item of vertical one, its horizontal child should expand. It works actually, but my inner RecyclerView's items are disappearing after expanding. If I call adapter.notifyDataSetChanged when State==Expanded inner recyclerview shows properly, but as you can imagine I cannot see expanding animation if I do that. Besides, I'm fetching photos from firebase and whenever I call notifyDataSetChanged this causes heavy network operation again and again.
Long story short, is there a way prevent my inner RecyclerView being disappearing so I won't need to call notifyDataSetChanged again? Thanks in advance.
Currently there's a check to consider the expansion complete if the expansionFraction is "close enough" to a final value.
This fixes the problem internally, but the wrong value is then exposed through the listener.
When I expand an ExpandaleLayout a second time the animation of stucks, but expanding the first time is no problem.
Does anyone know this problem and can help me.
Hi,
It really confused me that the releases page was out of date - I often look there in github repos to find the latest version. Perhaps if you are no longer using it you should delete the existing releases?
The expand/collapse causes big frame skipping on Nexus 7 device when this layout is used in recycler view, but behaves seemingly on other devices. What might be the cause of such behavior?
Implement same thing like website accordion. It has an icon as indicator to whether its expand or collapse.
Here an example :
https://roaderapp.com/faq.html
Is there a way to collapse all items in RecyclerView Adapter, when user clicks on one single item. That is only one item should be in expanded mode.
I think it is happen when click the any item. many time it expand from bottom of item. some time it expand from top side from item. and when i click first item in recycler view. it expand top side from item. and some time it expand bottom side. most time it expand top side. when it expand top side from item. this time the first item expanded view hide behind the toolbar. so this is the error i think. if u have any solution then give me. plaese give any solution
It would be nice to have a release notes for new versions of the library to have an overview of the changes/improvements.
Thank you for your work.
I have this code in RecyclerView:
<net.cachapa.expandablelayout.ExpandableLayout
android:id="@+id/expandable_note"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:el_duration="200"
app:el_expanded="false">
<View
android:layout_gravity="top"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@drawable/gradient_shadow"/>
<EditText
android:id="@+id/et_note"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_note"
android:padding="16dp"/>
</net.cachapa.expandablelayout.ExpandableLayout>
The error message is this:
android.view.InflateException: Binary XML file line #204: Binary XML file line #204: Error inflating class <unknown>
I tried to wrap the views to LinearLayour, RelativeLayout and Framelayout inside the ExpandableLayout, however, i still get the same error
It works only when I put single view inside the ExpandableLayout
<declare-styleable name="ExpandableLayout">
<attr name="el_duration" format="integer" />
<attr name="el_expanded" format="boolean" />
<attr name="el_parallax" format="float" />
<attr name="layout_expandable" format="boolean" />
<attr name="android:orientation"/>
</declare-styleable>
how to use layout_expandable attr? or how to realize it?
Sometimes before closing when the view is scrolled out(fling action) and recycled, the expandable layout bugs out with partially opened view with the height expanded only part way, when calling collapse on that the height doesn't reduce but the views inside disappear.
Also the duration is set as 1000ms.
Also sometimes it won't expand at all, also the expandable area is not a small one like in the example, its around 200dp in height.
Hi, thank you for this cool library! However, when I tried to use it in my project, syncing the gradle always results in
Error:(69, 13) Failed to resolve: net.cachapa.expandablelayout:expandablelayout:[latest_version]
I'm using latest Android Studio (2.3) and latest support library in my project. Importing this repo as module triggers error: com.novoda.bintray-release is not found
(can't find it in AS maven central lookup either).
Is there any additional step that I need to do to add this into my gradle dependency?
PS: I've also tried changing the [latest_version]
to 1.2.0
or any other version but the error still there. I've tried looking up your lib in the maven central lookup in AS, but there's nothing...
You should mention in your read me that if you're adding inflated views to the Expandable Layout programmatically you need to put the app:layout_expandable="true" attribute on the root view in your xml layout in order for it to work.
This is very convenient, No need to add extra repositories.
If expandableLayout is at the bottom of layout and child view(im using listView) going out of the screen to bottom, animation of expanding and collapsing start lagging. But if i have a lot of items in listView, animation disappears at all.
How can i fix it?
Issue: When I click a card item in a RecyckerView every 8th item is expanded as well as the item clicked.
Example: There are 24 items in a List. I click item position 1, it expands. Scrolling down the list, also the 8th item is expanded, 16th and 24th.
Expected behaviour: Only the clicked item is expanded
/**
* Toggle the expanded state on a card item
*
* @param holder The ViewHolder
* @param position The position of the card that was clicked
*/
public void toggleExpandedCard(ListViewHolder holder, int position) {
final String expandIcon = context.getResources().getString(R.string.mc_chevron_down);
final String collapseIcon = context.getResources().getString(R.string.mc_chevron_up);
Log.d(TAG, "Expanded position is: " + expandedPosition);
Log.d(TAG, "Clicked position is " + position);
// If nothing is expanded, expand as normal
if (expandedPosition == RecyclerView.NO_POSITION) {
holder.mExpandIcon.setText(collapseIcon);
holder.mDetailedView.expand();
expandedPosition = position;
return;
}
// If not clicking the currently expanded item
// Close the other first
if (expandedPosition != position) {
ListViewHolder expandedViewHolder
= (ListViewHolder) recyclerView.findViewHolderForAdapterPosition(expandedPosition);
if (expandedViewHolder != null) {
expandedViewHolder.mDetailedView.collapse();
expandedViewHolder.mExpandIcon.setText(expandIcon);
}
holder.mDetailedView.expand();
holder.mExpandIcon.setText(collapseIcon);
expandedPosition = position;
return;
}
holder.mExpandIcon.setText(expandIcon);
holder.mDetailedView.collapse();
expandedPosition = RecyclerView.NO_POSITION;
toggleExpansion(position);
}
Hi, can we have a listener for state changed ?. Something like: onExpaned, onCollapsed...
I tried to use onExpansionUpdateListener but the expansionFraction
param won't return the correct value 0 or 1, and it's performance related if I have to check expansionFraction
many times during the animation.
How to set maximum height in expandable layout ? , is it possible?
I am trying to change layout background color for collapsed and expanded view in a recyclerview, here I'm able expand and collapse the same view. But when I tried to tap other content the previously selected view background color remains unchanged. Is there any way to change the collapsed and expanded color background.
In RecyclerView, when I'm expanding my last visible element, it expands out of the screen. When I want to see the expanded layout I need to manually scroll RecyclerView. Is there an option to automatically scroll the RecyclerView so when I open last visible element it automatically scrolls the recyclerView as well?
When i click the item of recycler view . the item go upside of screen and hide below toolbar. issue come in recycle srollbar. when click of item item that still stand at one place and except whole recycler view go upside of screen and hide behind the toolbar
Hi Daniel,
I have a problem, and there is the link I posted in stackoverflow. Could you please help me with that?
Thank you.
http://stackoverflow.com/questions/42852161/expandablelayout-animation-not-smooth
I tried to create ExpandableLinearLayout programmatically but there is only one LayoutParams constructor LayoutParams(Context c, AttributeSet attrs)
.
Could you override other LinearLayout.LayoutParams
constroctors without AttributeSet
parametr?
if i scroll to the Expandable Layout Card view not scroll down
Hi, I am currently using your library for a layout that expands vertically in my project, and it works perfectly. But now I have a feature that needs another layout to be expanded from right to left (horizontal).
I can achieve this by using the old ExpandableLinearLayout
with android:orientation="horizontal"
and android:layoutDirection="rtl"
, but there is a glitch in the animation and it's deprecated anyway.
I try to use ExpandableLayout
but it somehow expands the layout from the middle, please help.
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.