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>
Related
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)
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.
I have to develop one android application.
Here i have to develop grid view layout like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/Layout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Mercuryminds Shoppingcart Application"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#040404"
android:gravity="center" />
<GridView
android:layout_height="wrap_content"
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:numColumns="auto_fit"
android:horizontalSpacing="10dp"
android:verticalSpacing="10dp">
</GridView>
<include
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/footer" />
</LinearLayout>
Here the layout footer is tab bar.
<?xml version="1.0" encoding="utf-8"?>
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:id="#+id/linearLayout1"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs">
</TabWidget>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#android:id/tabcontent">
</FrameLayout>
</LinearLayout>
</TabHost>
But i have to run the app means the tab bar is not display on my main view.whats wrong in my layout file.please help me.
add layout_weight="1" to your gridView and layout_height="0dp"
like this
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp" >
</GridView>
when i start my apps gridview show blue background i want to set white background how to set
here i put my xml and imge
Gridview.xml
<LinearLayout android:id="#+id/bodyfirst"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="15dp"
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="3"
android:drawSelectorOnTop="true"
android:gravity="center_vertical"
android:background="#android:color/white">
</GridView>
</LinearLayout>
you should add background to LinearLayout,this code is correct,for example
<?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"
android:background="#android:color/white">
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="115px"
android:numColumns="3"
android:drawSelectorOnTop="true"
android:gravity="center_vertical"
android:background="#android:color/holo_blue_dark" />
<GridView
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="100px"
android:numColumns="3"
android:drawSelectorOnTop="true"
android:gravity="center_vertical"
android:background="#android:color/holo_blue_dark"
android:layout_marginTop="13.0dp" />
</LinearLayout>
and you should add xmlns:android="http://schemas.android.com/apk/res/android" to LinearLayout
I have some problems with my grid 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:id="#+id/frag_books_grid_view_layout"
android:orientation="vertical">
<GridView
android:padding="0dp"
android:cacheColorHint="#color/bg_default"
android:listSelector="#drawable/list_selector_background"
android:id="#+id/frag_books_grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchMode="spacingWidth"
android:scrollbars="none"/>
</LinearLayout>
Single item:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
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:paddingLeft="15dp"
android:paddingRight="15dp"
android:id="#+id/frag_book_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="5dp"/>
</LinearLayout>
Problem is that there is no left and right padding of single item. And it looks terrible when item is selected: http://i.imgur.com/rirNP.png
Please, help to fix it.
try it
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu_category"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
for information
http://developer.android.com/guide/topics/ui/layout/gridview.html
this one is best for three columns..
<GridView
android:id="#+id/gridview_Gallery"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="65dp"
android:gravity="center"
android:horizontalSpacing="6dp"
android:listSelector="#00000000"
android:numColumns="3"
android:scrollbars="none"
android:stretchMode="columnWidth"
android:verticalSpacing="-1dp" />