Android: Layout used by wechat - android

In WeChat, it uses white sections for different things as you can see in below image there are three white sections in it and each item is separated by a black line:
I can suspect this is not a ListView as one might think in first glance.
Question: Does anyone know is this some built-in component that can be used or how to go about creating similar sections ?

I would say a linearlayout inside a scrollview with your custom listview and custom adapter is the most straightforward solution.
Each time the view is inflated you check the shared preference and fill in the info accordingly in your adapter. And on item click you open corresponding fragment/activity that do something. Then you issue a callback to refresh this settings view.
Might not be the most elegant way to do it. But I think this one is easy and clear.

I guess its a preferences activity/fragment but you can create it with a listview, linearlayouts or a combination of a scrollview and a linearlayout.
You have too many solutions ;)

Related

ListView with all items having different layout

Do we get any benefits of implementing a ListView for which every item would have different layout? Would it be a better idea to put those items into ScrollView with LinearLayout instead?
Intuitively, it seems like using a ListView may still give better performance, though it might be negligible depending on the size of your content. Because the ListView inflates the views as it needs them, it seems like you might save some time by not parsing/rendering views that a user might never see. A long ScrollView with a bunch of views inside seems like it would take additional time when first launched, since the view hierarchy is more complex.
I do think Michael is mostly correct though, that the main advantage of a ListView is that views are reused, which saves on memory/processing. Unless you have a ton of content in the ScrollView, I suspect the performance difference is not significant, and will almost definitely be more complex -- in particular, having to create an adapter that knows how to create each view type for each row.
I don't understand why you may use ListView for this. Listview is a list of common data using the same layout if you click on it. Users depend on same/similar GUI patterns.
How about Sliding Tabs or the newer navigation drawer, link NavigationDrawer.
If you like sliding tabs, then I can give you more details.

Which View/Widget can be used to display images on the screen one at a time by swiping horizontally?

I have a list view in which I want each list item will contain images. But the images will be displayed one at a time. SO, at a time for every list item only one image will be displayed. To view other images in the list item,one has to swipe horizontally. Is there any inbuilt widget that handles this in android?
EDIT1
My List item not only has Image but it also contains other views like textview, seekbar etc. So each list item will contain Image, textview, seekbar etc but the majority of the space will be occupied by the Image. Now, for each list item, when the image is swiped horizontally, another image has to be downloaded from a ulr and displayed.
EDIT2
I did a bit of research on ViewPager but many references like the answers here and this blog seem to suggest that using ViewPager inside a listview is not a good idea. Why is that? If it is not a good idea, what is a good alternative?
This problem can be solved by using ViewPager.
Link: http://developer.android.com/training/animation/screen-slide.html
ViewPager(for swiping between views) + UniversalImageLoader(for loading images from URLs, with caching etc)
If it is not, what is a good alternative?
I think you should use RecyclerView with LinearLayoutManager.HORIZONTAL. All things like recycling the views, view holder design pattern can be done easily with it and it is a new widget that google introduced and you can use it instead of ListView + ViewPager. because as you suggested it is not recommended to use viewpager inside listview. Although you can use horizontalScrollView but it dose not recycle the view. Other third party library like this exist but I recommend you use RecyclerView with LinearLayoutManager.HORIZONTAL because it is from google and it is normally tested more than people library. And another thing is you can use other layout manager like GridLayoutManager or having for example 3 rows that swiping horizontally or other good effects like adding animation and .... that google provided with RecyclerView.
For downloading the images you can use Picasso,Volley, Universal Image Loader or a lot of other libraries that exist.
Happy Coding :-)
Not sure I'm following you, but rather than a ListView wouldn't it be simpler to use ViewPager with simple Fragment that wraps a single image at a time. That way you get horizontal swiping "for free".
Do you just want swipe to change images? Or do you want the images to scroll as you swipe? For the former, you can just use a GestureDetector. For the latter you would probably use a ViewPager. See http://developer.android.com/training/animation/screen-slide.html
I have achieved the same functionality by using ViewPager, you can either put the SeekBar and TextView in the Fragment class off which you are gonna make multiple instances for each item and add to the pageradapter,
You can also add the TextView and SeekBar above the ViewPager Layout in your main fragment layout file and change the text and data on seekbar on viewpager's on item change listener, this looks more neat and this is the approach i've used

List menu that open hidden views in it

I need to create a list menu where each item, when selected, will open a sub area with others controls (see the example image):
I have two possible solutions in my mind:
Have all the item's controls in RelativeLayout with "gone" visibility, and list them in a LinearLayout.
Use the ExpandableListView, but I have no experience with that and I don't know if this might be a proper solution in my case.
What do you think would be more elegant? Do you have other/better solutions?
You can use ListView as well as ExpandableListView to achive your requirent.
I have done some thing by using ListView and slide animation that suits your requirement.
For Complete reference go through my Android blog
http://amitandroid.blogspot.in/2013/03/android-listview-with-animation.html
Thanks,
Both approach would work but ExpandableListView should be better performance-wise.
You must provide a ExpandableListAdpater, with a layout for your group item and another for the subitems.

expandable listview or clickable linear layout

I am trying to create something like (very poorly created in paint) in the image below:
I have only 4 items, and it won't be more. the items contains two textviews. But when you click on an item, i want it to expand, (like item 2) to the bottom with three extra buttons. It would be really nice if there would be some nice expand animation. I don't want this list to be scrollabe, it just need to fits in my screen. And only one can be expanded.
I think there are two options, but maybe i am missing something.
1) Create an itemlayout.xml, containing an linearlayout or something containing the extra buttons, set to linearlayoutbuttoncontainer.setvisibility(View.GONE). And then build a switch, which closes the others than the clicked one, and set the visibility of the clicked item to visible. This would be fairly easy to build i guess, i don't foresee a lot of problems. But is it possible creating an animation or is there only a sudden screen change?
2) expandable listview, with the buttons in the expandable item. I know its possible to make only one item expanded, by rembering the expanded one and closing it again. But is it possible to make it like this, with the buttons in the expandable part? Actually i've never used an expandable view.
Anyone know what the best solution should be?
Thanks
I would recommend using an expandable list view for this, as your second option described. For this type of list you can use a expandable listview adapter, describded here:
http://developer.android.com/reference/android/widget/ExpandableListAdapter.html
This adapter has both a getGroupView(open/close items) and a getChildView method in which you can inflate your layouts, or manually set them up. If you have used ordinary listviews I'm sure this wont be a problem for you, since it's basically the same operations.
This means you should probably inflate your childViews with a LinearLayout containing three buttons. Then you have to implement functionality for your collapse/expand logics by keeping track of which item index is opened.
I did this tutorial when I first started out with exp.list views, I found it helpful:
http://android-adda.blogspot.se/2011/06/custom-expandable-listview.html
Good luck!
You gotta check this http://udinic.wordpress.com/2011/09/03/expanding-listview-items/ it works neat. If you got any more problems, do ask...

SimpleCursorAdapter within a ScrollView

I'm having abit of an issue and i'm not too sure how to go about solving it.
Essentially i have an activity which has a base xml layout of ScrollView and i want this activity to list some results from a Cursor. So i thought i'd use SimpleCursorAdapter... however when i got it all set up it appears that the ListView that the SimpleCursorAdapter goes into doesn't play nice being within another scrollable layout element.
I've sorta got it working programmically but i'd much rather use a ListAdapter as it will make each list entry look like a button and keep it inline with the design of the rest of the application and can handle the ids of each item and where to send the user upon clicking.
So my question is this: is there anyway to either make ListView show all the items such that it never needs to scroll, or can i change the ListView to something like a LinearLayout?
I hope that makes sense!
Any help / insight / ideas are welcome!
Cheers!
You can NEVER use a scroll view and a ListView together. Its a mess! and illogical as well.
Here are some of the approaches you can use:
Theres no screen big enough to show all the content of you listView you can try wrapping up your content but as I said it won't help as scroll view and list view don't work together. So you can either remove your or
If your list items are simple you can dynamically add your views to LinearLayout with specified location
Another tip I can give you is you can always use an relative layout and place your listView alignParentBottom="true" and emit the scrollView approach this will make you listview alwyas scrollable.
It doesn't really make sense to have a ListView inside a ScrollView at all. The ListView implements it's own scroll function so it should not be used in conjunction with a ScrollView anyway.
You should rethink your UI design.
I agree with Shardul; trying to put a listview with a scrollview will make it impossible to scroll. Have a look at the links below to see what you can accomplish with just a ListView -
a.
custom backgrounds info.
custom adapters

Categories

Resources