I am using android:horizontalSpacing attribute in my GridView layout to give horizontal spacing between two columns. But nothing getting change only it give space between the vertical columns.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="2dp"
android:horizontalSpacing="2dp"
android:stretchMode="columnWidth"
android:numColumns="7" />
</FrameLayout>
This is the above code but i don't understand what is the actual mistake i am doing. You can see in above picture that , there are only black vertical lines but i also want horizontal black lines.
Please help me out , suggest me some solution.
Related
I have GridView in one of my android application layouts. I am trying to set Item in center of Gridview but its always stay on the left side. I have searched many similar questions in StackOverflow but not got my problem solved. My XML is like below. Let me know if anyone can help me to make my GridView items in the center.
<FrameLayout
android:id="#+id/framecaregory"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/second"
android:layout_alignParentTop="true"
android:layout_marginTop="?actionBarSize">
<GridView
android:id="#+id/gridviewcategory"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/lite_color"
android:numColumns="5"
android:visibility="gone">
</GridView>
</FrameLayout>
Thanks
The thing you want does not depends on grid Layout, but to its child layout which is adapted to it. First create another layout grid_item_row.xml and put:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/framecaregory"
android:layout_width="match_parent"
android:orientation="vertical"
android:padding="10dp"
android:gravity="center"
android:layout_height="wrap_content">
<TextView
android:text="Text in the center"
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
After that adapt this layout to grid layout
i am developing an android app where i am showing day wise channel schedule (multiple rows).
now in this i have to provide both vertical and horizontal scrollability.
vertical scrollability will be normal , but horizontal scrollability should be synchronized
that is when user scrolls horizontally all other rows should also be scrolled in a sync.
i tried using table layout but its not going good with my requirement and i have also tried TwoWayView but i am not able to sync the horizontal scrolling.
i would like to know i anyone have faced/solved the similar situation.
Any leads on this is highly appreciated.
xml for vertical and horizontal Scrolling :-
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/vertical_scroll_view2">
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/horizontal_scroll_view2">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="910dp"
android:id="#+id/scheduleContainer"
android:orientation="vertical"
/>
</HorizontalScrollView>
</ScrollView>
.....
xml for TwoWayView:-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/weekday"
android:layout_height="fill_parent"
android:layout_width="40dp"
android:textSize="12dp"
android:textStyle="bold" />
<com.mobiotics.tvb_stb.utilityclasses.TwoWayView
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/hlist"
style="#style/TwoWayView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_toRightOf="#id/weekday"
android:scrollbars="none"
android:drawSelectorOnTop="false"
tools:context="com.mobiotics.tvb_stb.activity.HomeScreenActivity" />
</RelativeLayout>
i am adding twoway list to linear layout .
If you can have a ListView, I would start there. Just drop the ListView into a HorizontalScrollView. Make sure to set the width of the HorizontalScrollView to wrap_content. I noticed you have it set to fill_parent.
I have a problem with grid view layout on Android. I can't find solution to eliminate extra space in grid view.I mention the code fro gridview as below :-
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:alwaysDrawnWithCache="true"
android:background="#android:color/background_dark"
android:clipChildren="true"
android:columnWidth="100dp"
android:gravity="center_horizontal"
android:horizontalSpacing="2dp"
android:numColumns="auto_fit"
android:padding="0dp"
android:scrollingCache="true"
android:smoothScrollbar="true"
android:stretchMode="columnWidth"
android:verticalSpacing="2dp" />
now my application's grid view look like this
As shown there is extra space which i want to remove it and it can look like this:-
So please provide me solution..
Thanks in advance..
You need to alter the value for android:columnWidth attribute for all layout types [hdpi,mdpi,xhdpi etc.] supported by your application.
You can use :
android:listSelector="#null"
to eliminate extera space
and try this , for 3 column cell:
android:numColumn = "3"
I have GridView:
<?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:id="#+id/frag_books_grid_view_layout"
android:orientation="vertical">
<GridView
android:cacheColorHint="#color/bg_default"
android:listSelector="#drawable/list_selector_background"
android:id="#+id/frag_books_grid_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:columnWidth="120px"
android:gravity="center"
android:horizontalSpacing="15dp"
android:scrollbars="none"
android:stretchMode="columnWidth"
/>
</LinearLayout>
And single item (placed in cell of this grid):
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:cacheColorHint="#color/bg_default"
android:scrollbars="none"
android:listSelector="#drawable/list_selector_background"
android:layout_gravity="center_vertical|left"
android:gravity="center_vertical|left"
android:padding="15dp"
android:id="#+id/frag_book_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="5dp"/>
How it looks: http://i.imgur.com/rhZiu.png
Everything is fine with blue selection, but the contents of the cell is not centered inside of it.
This picture explains what I want: http://i.imgur.com/OumWu.png
Besides it's not recommended to have nested scrollable components, you have the dimensions of list view set to match_parent. So it's not possible to center, since it's already occupying all available space.
If you want to center, you first have make the listView smaller (setting fixed size). And then use gravity="center" on the container. You also can apply a uniform padding to the container, this will also make the listView look centered.
I've got inflating vertical linear layout in my gridView.
When I display only the vertical layout element, there's no space between the two images of my layout.
But when I display the grid, there's a spacing between two grid lines and between my two images (verticaly) in each grid box.
How can I remove these spaces ?
Here is my main layout wich contains my grid :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_gravity="center">
<GridView android:id="#+id/GridView01"
android:verticalSpacing="0px"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:numColumns="3"
android:horizontalSpacing="0px"
android:stretchMode="none"
android:columnWidth="90px"></GridView>
</LinearLayout>
Here is my vertical layout of each elements grid :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LayoutP"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/greyr"></ImageView>
<ImageView android:id="#+id/ImageView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/greyp"></ImageView>
</LinearLayout>
Thanks in advanced.
Finally, I've found a "hack". It consists in setting a negative margin for the bottom of the first image, and the same negative margin for the top of the second one, as well as setting negative for the verticalSpacing grid.