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"/>
Related
I want to display a horizontal list of scrollable buttons at top of the phone screen containing 30 items, for this purpose I am using a HorizontalScrollView with a LinearLayout with "horizontal" orientation as it's child but the linear layout is not taking up the entire phone width even on setting its width as "match-parent". Here's the code :
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="center">
<GridView
android:id="#+id/gridView_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchMode="columnWidth" />
</LinearLayout>
</HorizontalScrollView>
Here is shown in the image that linear layout is not taking up the entire space and LinearLayout is only covering some of the space. Also on changing the size to a fixed size, I noticed that the HorizontalScrollView was actually behaving like a vertical Scroll View only.
NOTE: Also if there is an alternative way to display a horizontal list of buttons with 30 items with numbers from 1 to 30 on it, please suggest it.
To achive this easily you may use Recyclerview with Horizotanl Layout Manager.For Example
recycler_view.setLayoutManager(new LinearLayoutManager(MainActivity.this, LinearLayoutManager.HORIZONTAL, false));
I don't think you need a HorizontalScrollView with a nested LinearLayout for what you are trying to achieve. It would be a better idea to simply use a horizontal RecyclerView if your button layouts are similar and the functionality of the buttons is similar too. Refer to this answer for help https://stackoverflow.com/a/40584425/9119277
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"/>
This is what I have so far:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linearLayout1"
android:layout_marginBottom="100dip" >
</ScrollView>
Inside scrollview I want a grid of icons and possibly some other views, I plan to populate those through java code.
I've looked at both GridLayout and GridView and I'm struggling to determine which is better suited, my first gut instinct was GridLayout but some people suggest GridView is better suited to my purpouses.
What about adding
<Scrollable ......>
<GridLayout.....>
your components
</GridLayout>
</Scrollable>
This will make your page Scrollable whatever the insider Layout
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"
I have this xml file. The list contains 2 items. When I test the application on the SDK emulator or a tablet, it is displayed as intented. However, when I download the application on a Samsung GT-S5570 with Android v2.2.1, the user can drag the list from the top and move it towards the bottom of the screen. Is there any way to prevent this from happening?
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="20dip"
android:id="#android:id/list"
android:cacheColorHint="#android:color/transparent"
android:textAppearance="?android:attr/textAppearance"/>
</RelativeLayout>
If you just want to display limited number of items, then put that items within the ScrollView instead of using ListView.
ListView is intended to display unlimited number of items with scrollview to scroll other items.
This answer is the more informative and helpful: how can i automatically size listview so it doesn't scroll