I have two gridview in one scroll view, however the only gridview to scroll is the pink one
[
and gridview 3 is fixed, but i want the two gridview to scroll together
how it looks like, i don't know if you can actually see... but when i scroll the page, only the pink gridview scrolls, and this vertical gridview doesn't
[
and then it messes the numbers...
my scrollview code:
<!-- Items -->
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fillViewport="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Content itself -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/grid_content"
android:gravity="left"
android:horizontalSpacing="0dp"
android:verticalSpacing="0dp"
android:numColumns="6"
android:clickable="true"
android:background="#color/colorAccent"
>
</GridView>
</LinearLayout>
<!-- Numbers -->
<LinearLayout
android:layout_width="50dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_gravity="right"
android:background="#color/white"
android:gravity="right"
android:padding="0dp"
>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/grid_numbers"
android:gravity="right"
android:horizontalSpacing="5dp"
android:verticalSpacing="5dp"
android:numColumns="1"
android:clickable="true"
android:background="#drawable/border_vertical"
>
</GridView>
</LinearLayout>
</RelativeLayout>
</ScrollView>
I think that gridview already have a scrollbar. Therefore, it "overrides" your scrollview behavior, and then the gridview 3 does not scroll.
You should consider using only one gridView.
Edit :
If for some reasons you don't want to, I'd suggest to overwrite "onTouch" functions in order to prevent grid 2 and 3 to catch the touch event, and therefore, allowing the scrollview to deal with it.
However, this approach may lead to further problems if you need to catch other behaviors (click, move, ...)
Related
this is my code ,
i want visiable horitonzal scrollbar in gridview , so i tried to fix it , my gridview have 1row and 3 Columns , icant use vertical scroll because content page have scroll
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_below="#+id/linearLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:id="#+id/linearLayout3"
android:background="#android:drawable/dialog_holo_light_frame">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="طرح های پیشنهادی"
android:id="#+id/textView3"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:layout_gravity="right"
android:textColor="#cc0066"
android:textStyle="bold" />
<GridView
android:id="#+id/gridview1"
android:layout_width="match_parent"
android:layout_height="80dp"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:verticalSpacing="5dp"
android:numColumns="auto_fit"
android:scrollbars="horizontal" />
</LinearLayout>
</HorizontalScrollView>
you can either enable nestedscrolling in xml or you can enclose your gridview inside a nestedScrollView . Try that , if that's not working let me know.
Did you try to add ScrollView?
HERE is that people already talked about that. If i didn't understand you wrong.
I adding example codes for vertical and horizontal.
How to scroll gridview to position?
How can I add a vertical scrollbar to a gridview?
Firstly, end of the LinearLayout, get rid of the slash: /> to >
Here is direct answer for your question:
Put into ScrollView:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="vertical">
<!-- your codes here -->
</ScrollView>
For horizontal:
<HorizontalScrollView>
<ScrollView>
<!-- your codes here -->
</ScrollView>
</HorizontalScrollView>
I use a vertical ScrollView to carry ViewPager and Gridview. ViewPager's position is above the Gridview,and Gridview is use "expand all" to keep it behaviors well inside scrollview.
But. After I use adapter to fill content to these two view. The position is always scroll to Gridview's position at first.User need to scroll it up to see Viewpager themself.
I want its position can at the first viewpager, not the gridview.
Could you give me some suggestions.
Thanks.
The following is my layout file.
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:scrollbarAlwaysDrawVerticalTrack="true" >
<LinearLayout
android:id="#+id/linearlayout_dynamicRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/viewpager_fl"
android:layout_width="fill_parent"
android:layout_height="160dp" >
<myViewPager
android:id="#+id/vp"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="40dp"
android:background="#B0000000"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/ll_dot_dynamic"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="0dp" />
</LinearLayout>
<TextView
android:id="#+id/tv_title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:ellipsize="end"
android:gravity="center_vertical|center_horizontal"
android:maxLines="1"
android:textColor="#FF7700"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/tv1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="GridView_Header1"
android:textColor="#ff7700"
android:textSize="20dp"
android:visibility="gone" />
<GridView
android:id="#+id/gv1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</GridView>
</LinearLayout>
</LinearLayout>
</ScrollView>
Further reading has revealed that there are issues with scrolling components inside scrolling components.
One solution is to 'disable' the vertical scrolling of the ScrollView on the area of the contained scrollable component, in my case a ViewPager.
The code for this solution is detailed here(HorizontalScrollView within ScrollView Touch Handling) (and its simply brilliant!)
I have made a gridview and listview inside a LinearLayout. data that display is dynamic. gridview fill the 80% of the screen height.and listview have only 20% of screen height and in it items are scrollable but due to availability of screen height listview display only 2 items at a time..
now i want parent of listview and gridview is scrollable but gridview and listview are not so that list view can show more than 2 items at a time.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="vertical" >
<include layout="#layout/app_headerview_imageview_textview" />
<GridView
android:id="#+id/gridView"
android:layout_width="match_parent"
android:layout_height="0dip"
android:listSelector="#null"
android:numColumns="3"
android:layout_weight="1" >
</GridView>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#112F51"
android:orientation="horizontal"
android:padding="20dip" >
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/diagnose_button_selector"
android:text="Auto Diagnose"
android:textColor="#ffffff"
android:textSize="#dimen/small_text_size"
android:padding="#dimen/padding_medium"/>
<View
android:layout_width="0dip"
android:layout_height="1dip"
android:layout_weight=".2" />
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/diagnose_button_selector"
android:text="Diagnose Now"
android:textColor="#ffffff"
android:textSize="#dimen/small_text_size"
android:padding="#dimen/padding_medium" />
</LinearLayout>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#E6E6E6"
android:orientation="vertical" >
<include layout="#layout/bottom_action_bar" />
</LinearLayout>
A scollview should only have one direct child.
You should never use a ScrollView with a ListView, because ListView
takes care of its own vertical scrolling. Most importantly, doing this
defeats all of the important optimizations in ListView for dealing
with large lists, since it effectively forces the ListView to display
its entire list of items to fill up the infinite container supplied by
ScrollView.
If you want to have more of the listview available on the screen, giving the fact that gridview is also scrollable, you should use the weight property for both children of the LinearLayout so that they take up similar amounts of space on the screen
I want my whole activity to scroll at once, but the ListView which is embedded in my ScrollView won't expand. I just see the first row, but I can scroll through the other rows, when scrolling the listView.
What I need is for the listView to expand in height so every items it contains are displayed without having to scroll the listview, only the main scrollView...
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="vertical"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/header_Layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
...
</LinearLayout>
<TextView
android:id="#+id/comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#drawable/gradient_background"
android:text="#string/comments"
android:textColor="#000000"
android:textStyle="bold" >
</TextView>
<ListView
android:id="#+id/commentsListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill"
android:divider="#drawable/gradient_divider"
android:dividerHeight="1dp" />
</LinearLayout>
</ScrollView>
One of the main purposes of a ListView is to enable recycling of cells while scrolling. If you want all the cells to exist, then you don't need a ListView. Just use a vertically oriented LinearLayout.
I want to display the grid view elements in only one row that means i want horizontal scrolling in grid view.Each time i want to display only 5 elements only in one row.For this give me some suggestions.Thanks in advance.
below is the my layout code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="#+id/ImageViewlarge"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</ImageView>
<TextView
android:id="#+id/TextViewImageName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:editable="false">
</TextView>
<LinearLayout
android:layout_width="fill_parent"
android:orientation="horizontal"
android:gravity="bottom" android:layout_height="fill_parent">
<ImageView
android:id="#+id/ImageViewLeft"
android:clickable="true"
android:focusable="true"
android:layout_alignParentLeft="true"
android:src="#drawable/leftarrow" android:layout_height="50sp" android:layout_width="30sp" android:layout_gravity="bottom|left">
</ImageView>
<GridView
android:id="#+id/GridView01"
android:scrollbars="horizontal"
android:layout_height="wrap_content"
android:fadingEdge="horizontal"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarAlwaysDrawVerticalTrack="false"
android:numColumns="5" android:layout_gravity="center_horizontal" android:layout_width="260sp">
</GridView>
<ImageView
android:id="#+id/ImageViewRight"
android:clickable="true"
android:focusable="true"
android:src="#drawable/rightarrow" android:layout_width="30sp" android:layout_height="50sp" android:layout_gravity="right"/>
</LinearLayout>
</LinearLayout>
in that above code now i want to remove the that 2 image view and set the horizontal scroll to that grid view elements.For this give me some suggestions,Thanks in advance
I believe the same effect could be achieved by using a LinearLayout with the orientation set to horizontal. The LinearLayout can be embedded in a HorizontalScrollView
The documentation on HorizontalScrollView actually says this:
A HorizontalScrollView is a
FrameLayout, meaning you should place
one child in it containing the entire
contents to scroll; this child may
itself be a layout manager with a
complex hierarchy of objects. A child
that is often used is a LinearLayout
in a horizontal orientation,
presenting a horizontal array of
top-level items that the user can
scroll through.