scrollView not working android - android

I see the scroll line but it is not working. This is the code:
What could be the reason?
The layout:
<ScrollView xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/titleshopandsell"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:text="פריטים שתוכל למכור"
android:textColor="#880000"
android:textSize="12sp" />
<GridView
android:id="#+id/gridView1"
android:numColumns="auto_fit"
android:gravity="center"
android:verticalSpacing="3dp"
android:horizontalSpacing="2dp"
android:columnWidth="130dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</GridView>
</LinearLayout>
</ScrollView>
What is the problem with my code?

GridView is also a special type of ScrollView.. you should change parent scrollView to Relative/Linear Layout.
Currently Both scrollView and GridView obstruct the proper scrolling.

Related

Unwanted Gridview spacing

My grid design is as such. But i want to remove the spaces on both sides of the grid elements. (Black marked)
I want the image to be expanded somewhat like
My XML layouts for the gridview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context=".MainActivity" >
<GridView
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="100dip"
android:gravity="center"
android:numColumns="2"
android:stretchMode="spacingWidthUniform" />
</LinearLayout>
My grid element layout
<?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" >
<ImageView
android:id="#+id/grid_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:contentDescription="#string/im" >
</ImageView>
<TextView
android:id="#+id/grid_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:maxLength="23"
android:gravity="center"
android:layout_marginTop="10sp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:textSize="12sp" >
</TextView>
</LinearLayout>
Try Changing
<GridView
android:id="#+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:verticalSpacing="1dp"
android:horizontalSpacing="1dp"
android:numColumns="2"
android:background="#abcdef"
android:stretchMode="columnWidth" />
You can replace GridView with GridLayout and use weights to make the images fill the screen. Here's the reference: http://developer.android.com/reference/android/widget/GridLayout.html, (See the section: Excess space distribution)

How to place gridView to the center of screen

How can I place my programmatically filled gridview to the center of screen.
It is always on the top.
I can place my gridview to the centerm if it is included to the scrollView.
But in this case I can only see first cells of gridview (other not visible)
The XML is here:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/backNormal"
android:orientation="vertical"
>
<include layout="#layout/adview" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/backNormal"
android:orientation="vertical"
android:layout_gravity="center_horizontal|center_vertical"
>
<GridView
android:id="#+id/gridViewTopics"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/backNormal"
android:gravity="center"
android:layout_gravity="center_horizontal|center_vertical"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"
/>
</LinearLayout>
</LinearLayout>
Any ideas please? Thanks!
Try this way,hope this will help you to solve your problem.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backNormal"
android:orientation="vertical">
<include layout="#layout/adview" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#color/backNormal"
android:orientation="vertical"
android:gravity="center">
<GridView
android:id="#+id/gridViewTopics"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#color/backNormal"
android:gravity="center"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="5dp"
android:horizontalSpacing="5dp"/>
</LinearLayout>
</LinearLayout>

GridView not centering; aligned right

I can't figure out where this left padding is coming from.
My grid is not just uncentered, it appears to be aligned to the right. What's up with this?
Layout:
<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:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp"
android:paddingBottom="8dp">
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridView"
android:numColumns="auto_fit"
android:columnWidth="240dp"
android:stretchMode="spacingWidthUniform"
android:verticalSpacing="22dp"
android:horizontalSpacing="16dp"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent = "true">
</GridView>
</RelativeLayout>
I believe it is coming from the line
android:stretchMode="spacingWidthUniform"
Remove that and test it out.
Try this tag
android:gravity="center" in GridView
As
<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">
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridView"
android:numColumns="3"// Changed to 3
android:columnWidth="60dp"
android:stretchMode="columnWidth"// Added
android:verticalSpacing="22dp"
android:horizontalSpacing="16dp"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
</GridView>
</RelativeLayout>

Android: Overlap in ExpandableListview & Listview

In my android application i have an expandableListView and Listview. In ListView I am getting data from Webservice. Then data loads into ListView some kind of overlap between ExpandableListView and ListView Items i want to one of them is hiding under other. How can I achieve it?
Please find below the image of my application.
My Xml code
<?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:orientation="vertical"
android:descendantFocusability="blocksDescendants">
<GridView
android:id="#+id/listView1"
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="100dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</GridView>
<ExpandableListView
android:id="#+id/lvExp"
android:layout_width="wrap_content"
android:layout_height="135dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:divider="#00000000"
android:groupIndicator="#drawable/group_indicator"
android:stackFromBottom="true" >
</ExpandableListView>
<ListView
android:id="#+id/listView2"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/listView1"
android:layout_marginTop="37dp"
android:divider="#00000000"
android:listSelector="#android:color/transparent" >
</ListView>
</RelativeLayout>
Please note that you are using GridView not ListView at least in this code, your ListView is commented currently.
Now if you want to have ExpandalbleListView below ListView add
android:layout_below="#id/listView1"
to your ListView. You are using RelativeLayout and this layout create as z-axis making it possible to overlap view over each other. So, in RelativeLayout you have to specify where a view should be positioned with respect to other `views.
Try this.
<?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:descendantFocusability="blocksDescendants"
android:orientation="vertical" >
<GridView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.4"
android:columnWidth="100dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>
<ExpandableListView
android:id="#+id/lvExp"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_weight="0.4"
android:divider="#00000000"
android:stackFromBottom="true" >
</ExpandableListView>
<ListView
android:id="#+id/listView2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="10dp"
android:layout_weight="0.2"
android:divider="#00000000"
android:listSelector="#android:color/transparent" >
</ListView>
</LinearLayout>

ListView not scrollable

My ListView does not receive onScroll events in case it is short and does not fill the whole screen, which is strange, because I have set fill_parent as height.
My layout:
<?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:background="#drawable/bg_login_screen3"
android:orientation="vertical" >
<CheckBox
android:id="#+id/overview_allcars_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/all_cars"
android:textSize="14sp" />
<LinearLayout
android:id="#+id/list_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:cacheColorHint="#00000000"
android:fadingEdge="horizontal"
android:scrollingCache="true" />
</LinearLayout>
</LinearLayout>
You may find this answer useful:-
Making TextView scrollable on Android
Thats what helped me there:
<ScrollView
android:id="#+id/SCROLLER_ID"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:fillViewport="true">
<TextView
android:id="#+id/TEXT_STATUS_ID"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1.0"/>
</ScrollView>
Mainly you wrap your TextView in a ScrollView.

Categories

Resources