Now i going on with the MergeAdapter to show the list of data in vertical view and successfully showed it.Now what i need to show it in MergeAdapter horizontal list and also search a lot for MergeAdapter horizontal listview.
Is it possible to show listview in MergeAdapter horizontal view if there please help me.
Should achieve this by MergeAdapter horizontal listview.
There is no supported horizontal listView in android. I have no idea about MArgeAdapter but if you want to use Horizontal you need to constructer a xml like that
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="#dimen/paddingLeft"
android:paddingTop="#dimen/paddingRight" >
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="#dimen/paddingTop">
<LinearLayout
android:id="#+id/scrollViewContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
and add views inside scrollViewContainer. Also check this How can I make a horizontal ListView in Android?
MergeAdapter has nothing to do with being vertical or horizontal. MergeAdapter is just an Adapter. The visual representation of the collection is up to the AdapterView, which can do scrolling vertically, horizontally, bi-directionally, diagonally, or not have scrolling at all.
So, find yourself an AdapterView that can serve as a horizontal ListView. Or, use RecyclerView for the horizontal-scrolling list and handle your merging by some other means.
Related
I'm developing a endless scrollable list for an android app, using the RecyclerView viewgroup and an OnScrollListener where i add the items after the user scrolled to the last item of the RecyclerView.
Now a want to add a black line in the middle behind the items as kind of a recycler view.
As you see, the items can have different heights.
Whats the best (and most performant) way to archieve this?
You might consider using a layout like the following.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/your_background">
<android.support.v7.widget.RecyclerView
android:id="#+id/your_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent" />
</RelativeLayout>
I need to display a staggered grid within a linear layout.
For that I have used a StaggeredGridLayoutManager on a RecyclerView from android.support.v7.widget. The problem is that StaggeredGridLayoutManager doesn't support wrap_content.
There are other questions addressing the issue, but they are concerned with linear layouts, not staggered grids:
Not able to add empty view below Recyclerview
How do I make WRAP_CONTENT work on a RecyclerView
As far as I understand I could derive StaggeredGridLayoutManager and implement onMeasure. Is there a way do to that without recalculating the positions and sizes of the children myself? When looking at the StaggeredGridLayoutManager.java source, I can see that it uses ScrollbarHelper to approximate the size of the scrolling content. Is there a way to reuse that?
The problem is that when RecyclerView is drawn, it calculates all the remaining size to itself before drawing the next elements and don't recalculate after the other elements are drawn, leaving them outside the screen.
There is an easy fix for this problem: The trick is to draw all other elements first, and leave RecyclerView for last. Use a relative layout and put the RecyclerView last on the XML layout file. Since with relative layout you can put each element wherever you want independently of the order on the XML file, you will draw all elements before RecyclerView and this will make it calculate the accurate remaining space and wrap_content will work properly.
Example to add a paginagion bar below the RecyclerView:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity"
>
<LinearLayout
android:id="#+id/pagination_btns"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"> //HERE YOU ALIGN THIS ELEMENT TO THE BOTTOM OF THE PARENT
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/previous_btn_label"/>
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/next_btn_label"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/items_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:layout_above="#id/pagination_btns"/> //HERE YOU ALIGN THE RECYCLERVIEW ABOVE THE PAGINATION BAR
</RelativeLayout>
I ended-up using a custom control for this, inspired by:
https://github.com/expilu/AntipodalWall/blob/master/library/src/com/antipodalwall/AntipodalWallLayout.java
I'm using an expandable list view in an alert dialog (custom).
I am setting the view for the list like this:
alertDialogBuilder.setView(myView);
However i notice that the list doesn't stretch to occupy the whole view and i have to scroll within that list as shown in the image below:
Here's my xml code as well:
<ExpandableListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listview"
android:layout_width="match_parent"
android:background="#android:color/white"
android:groupIndicator="#null"
android:scrollbars="none"
android:layout_height="wrap_content"
/>
Has anyone ever had this problem before or know how to tackle it, i could set the height of the expandable listview but i wan't to refrain from that.
I have a simple list view which is placed inside a Horizontal Scroll view so that I can scroll horizontally when the list view content is too long. When I place Text View inside the horizontalScrollView, I could scroll horizontally. But, with list view it doesn't work.
Any body had the same issue? Any work around for this?
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/newListBoxContainerHSV"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:background="#FF00FF">
<ListView
android:id="#+id/list_view"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#FFFF00"
>
</ListView>
</HorizontalScrollView>
Because ListView is not meant to be put inside any ScrollView. It's considered a bad practice, as ListView itself has a built-in ScrollView and you may use it, so try avoiding at any price a ListView inside a ScrollView.
If necessary, redesign your layout to not need it, as it goes against Android's design.
I have a fragment with a textView giving instructions, and below a gridView. I wanted for the textView to scroll upwards with the gridView. In other words: for textView to disappear off screen when gridView is scrolling.
My idea of how to accomplish this is to give the gridView a fixed height that would make the entire layout scrollable - including the textView. However, up until I cannot achieve this. Is there a way to do this?
Layout no scroll:
When scrolled:
Any help/advice would be appreciated.
My layout XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/LightGrey"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical" >
<TextView
android:id="#+id/chooseLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="18dp"
android:text="#string/chooseLine"
android:textAppearance="?android:attr/textAppearanceLarge" />
<GridView
android:id="#+id/gridLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="130dp"
android:fitsSystemWindows="false"
android:gravity="center"
android:horizontalSpacing="5dp"
android:numColumns="auto_fit"
android:paddingTop="0dp"
android:stretchMode="columnWidth"
android:verticalSpacing="25dp" />
</LinearLayout>
Achieving this is is not going to be trivial. What you need is ListView's capability to add a header view, but unfortunately, GridView doesn't offer that functionality.
What I have done in the past to solve this problem is to convert the GridView to a ListView, and then add the header to the ListView. I created a wrapper adapter that takes the original adapter and combines a horizontal row's worth of grid cells into a single list row.
The tricky parts include: dynamically adapting the number of columns in a row based on the width of the screen, accounting for all combinations of view types within a row and remaining empty columns in the last row, and handling click interactions properly.
Put the whole LinearLayout in a ScrollView (How to use ScrollView in Android?) and for the GridView set android:layout_height="wrap_content"