I'm looking at best way of creating an Accordion-style widget such as on this page. Is there a way of achieving same effect using standard Android toolkit or do I need to build custom widget? If so - which one would you recommend extending if any?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I have to risk myself and say that the @Bostone answer is the most appropriate. I will give you my code below so you can see. Thanks for the GitHub Maciej Łopaciński, but as @SudoPlz said in the comments, there is no documentation at all. I didn't knew where to start. I try to do it with Eclipse and Android Studio and in neither I could run the project to start figuring out how its work. Besides, the last commit in that project was about 1 year ago, wich makes me fear a lot that if something goes wrong I will be stuck in a dead end. So without further delay, here is my solution based in @Bostone:
1.- First you have to create a Button and a Layout nested in a ScrollView:
2.- After that go to your corresponding JAVA, there find the button and set an onClickListener, inside the onClickListener you will find the layout.
3.- So now inside the onClickListener we will find the layout. As you can see in the first step the layout is set by default to
GONE
, but now we have to set it to visible. The problem is, how can I make it gone again and vice-versa? So we will add a condition for getting the visibility of the layout and based on that it will be hidden or show up:This can be put over each other as many times you want.
So now if you really want to make it look like an accordion you can pimp the button. You could put an arrow on the right of it, using by example:
You should do that inside the onClickListener and use the condition to change the direction of the arrow, by changing the drawable (if is gone and down arrow, and if is visible an up arrow).
Also, you can make it look more natural by adding an animation, like this:
You will have to consider that the above animation must be done while the view is visible. Please be aware that
setFillAfter(true)
, will change the size of the container permanently so if you do so, maybe you don't want to useVIEW.GONE
anymore. This question has a wonderfull explanation about the Scale AnimationI have pushed android accordion view project at github. We use it for our customers, tested on 2.2, 2.3.x, 3.2 and 4.0.3. Works pretty good for us.
Going to add animation on fold/unfold in next step.
Here is small screenshot:
In my app, I used Riya Gayasen's accordion view. It was very easy to get started and worked well. Here is what I did.
include ':app',':easyaccordion'
implementation 'com.riyagayasen.android:easyaccordion:1.0.3'
And in case you still wonder - this can be pretty much done with pair of button/layout stacked inside of the linear layout. Pseudo code follows
Another thing to possibly try is stacking ExpandableListView-s on top of each other