how to have a horizontal gridview at the end of scrollview - android

I have a scrollview that contain details of an item in my android app, what I need is to add a horizontal list of similar items (each inflate from a layout) at the end of this view. can anybody tell me how to do this?
P.S: I've tried Recyclerview and gridview and a library form this link but all of them are not working inside the scrollview !!!

Take a look at recent-images Library. It provides horizontal gridview(one row). Just add this library dependency and put below code in bottom of your scrollView.
<com.jess.ui.TwoWayGridView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#E8E8E8"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:columnWidth="70dp"
app:rowHeight="70dp"
app:numColumns="auto_fit"
app:numRows="auto_fit"
app:verticalSpacing="16dp"
app:horizontalSpacing="16dp"
app:gravity="center"/>

Related

Make gridview fill horizontally

I'm trying to make a list with a GridLayout that has two rows and scrolls horizontally. My problem is that the gridview automatically adds views from top to bottom across the screen (Vertically) instead of filling an entire row before filling the next column (Horizontally).
Images of what I'm talking about:
try this
android:numColumns="auto_fit"
auto_fit Display as many columns as possible to fill the available space.
Take a look at recent-images Library. It provides horizontal gridview(one row). Just add this library dependency and put below code in your xml.
<com.jess.ui.TwoWayGridView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#E8E8E8"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
app:columnWidth="70dp"
app:rowHeight="70dp"
app:numColumns="auto_fit"
app:numRows="auto_fit"
app:verticalSpacing="16dp"
app:horizontalSpacing="16dp"
app:gravity="center"/>

Using ScrollViews layout into HorizontalScrollView

I want to create a sort of card layout with cards that contain a ListView layout inside a HorizontalScrollableView that can scroll the cards horizontally. Everything is working but I have problem with scrolling. I can scroll the listview vertically only if I am not scrolling the cards horizontally and viceversa.
This is the main container:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<HorizontalScrollView
android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ddd" >
<LinearLayout
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
I inflate and add the listview items to the linear layout.
I would like to allow vertical and horizontal scrolling smoothly without these kind of limitations (simultaneous horizontal and vertical scrolling).
How can I achieve this?
Check out this, might help you implement custom two-way scrolling layout.
https://github.com/ened/Android-Tiling-ScrollView/blob/master/src/asia/ivity/android/tiledscrollview/TwoDScrollView.java
If you want any of ListView features though (like view recycling, filtering, adapters) - things are going to get more complicated.
I would suggest you to take ViewFlipper to give scroll effect horizontally. Then add ListView to flipper as a child. Use gesture to move it right and left.
ListView will still scroll vertically and if you are not able to set OnItemClickListener to ListView then you can use SingleTap method of Gesture.
ListView inside View flipper discussion 1 and ListView inside View Flipper Discussio 2
I would suggest having your horiziontallayout as the root view you return in getView() in you adapter. That way each row will scroll separate from each other. If that doesn't work right away you may have to setItemsCanFocus(true) for your rows to give the input to your horizontalscrollview.

Android: HorizontalScrollView in a ListView row Item, focus issue

I have a ListView that each item has a layout that contains a HorizontalScrollView.
the problem is that I can't get the whole list item to be focused on when the user clicks or touches a list item.
how can I solve this ?
Thanks
Edit: the HorizontalScrollView looks like this:
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none"
android:focusable="false"
android:fadingEdge="none"
android:layout_weight="1"
android:id="#+id/scrollView"
></HorizontalScrollView>
OK Guys, I got it.
in the LinearLayout wrapping my HorizontalScrollView I added the following attribute:
android:descendantFocusability="blocksDescendants"
so the HorizontalScrollView did not receive focus.
thanks
The Layout looks very complex with HorizontalScrollView inside a ListView. You should simplify your UI. Use a ExpandableListView. I feel it suits your UI requirement right.

Scrollbar does not scroll while using dynamically filled listview

I am not able to scroll in a scrollview which contains a listview and is filled dynamically as I get data from the webservice.
I am able to do scrolling in emulator through mouse wheel, but in avtual device I can not scroll the list.
The attributes of scrollview are
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:layout_weight="0.6"
android:fillViewport="true"
android:orientation="vertical"
android:padding="6.0dip"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarFadeDuration="5000"
android:scrollbarSize="20dp"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="2dp" >
<ListView
android:id="#+id/listbox_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="599.84"
android:minHeight="250dp" >
</ListView>
</LinearLayout>
</ScrollView>
Please help me soon
by just looking at the layout_width and layout_height of your elements, it's clear that your scrollview will not scroll. unless you have a fixed height listview, never put a listview inside a scrollview (or in this case, a listview inside a layout that sits inside a scrollview).
I don't have any links to back this up right now, but it's not possible, and a well-known 'problem'. If you google a bit, or search here on SO, you'll find a number of topics covering this.
The problem arises in most cases when you have a scrolling view inside another scrolling view in the same direction. Consider the following example:
You have Two lists inside of a ScrollView.
Both lists are exactly one screen tall.
How do you scroll down to the second list?
When scrolling, how will your layout know if you are scrolling the list or the container?
This is basically the question that is the cause, and the only official solution is that it is as it should be, and there won't be a fix. Usually it is enough to have either a ListView or a ScrollView, but I have faced cases when you must have a listview in a scrollview (in my case a client wanted an iPhone-like datespinner in a scrolling page).
I solved it by using a FrameLayout, containing a custom ScrollView, and a ListView on top of that. Then in the code for the custom ScrollView, I added a line in the onScroll method that updated the top margin of the ListView, to psuh it upwards or downwards as the user scrolled. Surprisingly it worked.
NOTE: remember that:
The ListView handles its own scroll. If all you need is a scrolling
list, you do not need a ScrollView.
If you need a layout with a list and space for buttons or other
views, consider creating your layout so that the list only covers
enough space for you to fit your other views below/above without
scrolling.
Add following in your linear layout
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"

list inside scrollview

On my screen I have a list view and a button. my list has like 8 item. I would like my screen to scroll if both these items does not fit in. I don't want my list to have scroll but the complete layout including both list & button. If I use the below layout it only shows on item inside the list and I have to scroll within the list to go to next item.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<LinearLayout
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#android:id/list"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:background="#drawable/round_background" />
<Button android:text="Search" android:id="#+id/carSearchButton"
android:layout_gravity="center_horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
You can't put a ListView inside a ScrollView. Of GridView, or whatever View that handles scrolling on the same axis as the ScrollView does. That way the framework wouldn't know which View should handle the scrolling event. This layout won't produce an error when you compile it, but it won't work properly.
What you should do here: dump the outer ScrollView, you don't need it. Only use a ListView, and add the button to the ListView, using .addFooter(), that's the easiest way. This way your button'll appear as a list element, but you don't have to mess around with a custom adapter.
Scythe kind of answers my question but I wanted more then one one control below the list also on another screen I wanted 2 lists. So in order to have the scroll bar working with list view I had to fix the height of the list.

Categories

Resources