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>
Related
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>
I would like to display on the same page a viewpager and a gridview like this one ![What I would like :)][1]
[1]: http://i.stack.imgur.com/Xzg7T.jpg but what i get is that ![what I got][1]
[1]: http://i.stack.imgur.com/iZxwU.png .
There are my layouts.The Gridview Item
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/frag_Acc_gridView_imageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#215487"
android:scaleType="centerCrop"
android:src="#drawable/ic_logo"/>
<TextView
android:id="#+id/frag_Acc_gridview_textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/frag_Acc_gridView_imageView"
android:layout_alignParentLeft="true"
android:background="#80000000"
android:gravity="center"
android:paddingLeft="15dp"
android:textColor="#ffffffff"
android:textSize="20sp"
android:text="#string/hello_world" />
</RelativeLayout>
GridView 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" >
<GridView
android:id="#+id/fragment_acc_gridview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" >
</GridView>
</LinearLayout>
the main layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="10"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/fragment_acc_viewpager"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="6">
</FrameLayout>
<FrameLayout
android:id="#+id/fragment_accueil_gridview"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="4"
>
</FrameLayout>
</LinearLayout>
thanks
Take a look of this. You will get some help:-
http://www.rogcg.com/blog/2013/10/20/working-with-fragments-and-viewpager-on-android
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>
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" />