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
Related
I'd like to divide my layout screen into two parts:
Half with a ScrollView
Half with a ListView
Is it possible?
Thanks :)
Horizontally :
<?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="horizontal"
android:weightSum="2" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#192832" >
</ScrollView>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#193222" >
</ListView>
</LinearLayout>
Vertically :
<?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"
android:weightSum="2" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#192832" >
</ScrollView>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#193222" >
</ListView>
</LinearLayout>
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>
I have a vertical linearlayout, it has inside two linearlayout with diferent elements, I would like to fix the first one to the top, and the second one centered, I'm trying it but doesn't work:
<?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"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_bg"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#3b5998"
>
elements
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="300dip"
android:layout_height="300dip"
android:background="#drawable/background_resto"
android:gravity="center"
>
elements
</LinearLayout>
</LinearLayout
Why is it not working? Thank you in advance
I'd advice to choose a RelativeLayout for that purpose.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/holo_blue_bright"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentTop="true"
android:background="#fff" >
</LinearLayout>
<LinearLayout
android:layout_width="300dip"
android:layout_height="300dip"
android:layout_centerInParent="true"
android:background="#android:color/holo_green_light"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
This will help you to set the exact "relative" position in relation to other views.
Best wishes,
Tim
should use RelativeLayout instead of LinearLayout
<?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"
android:background="#drawable/background_bg"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:background="#3b5998"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
>
elements
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="300dip"
android:layout_height="300dip"
android:background="#drawable/background_resto"
android:layout_centerInParent="true"
>
elements
</LinearLayout>
</RelativeLayout>
<?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:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_bg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="50dip"
android:layout_alignParentTop="true"
android:background="#ff0000" >
</LinearLayout>
<LinearLayout
android:layout_width="300dip"
android:layout_height="300dip"
android:layout_centerInParent="true"
android:background="#ff0000"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
</LinearLayout>
I want to do like this, which layout should i use? so that it should be compatible for all screen?
thank you
use LinearLayout Like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:background="#color/blue"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="220px"
android:background="#color/gray"
android:layout_height="fill_parent"/>
<LinearLayout
android:orientation="vertical"
android:layout_marginLeft="40px"
android:background="#color/blue"
android:layout_width="220px"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:background="#color/gray"
android:layout_width="fill_parent"
android:layout_height="380px"/>
<LinearLayout
android:orientation="vertical"
android:layout_marginTop="20px"
android:background="#color/blue"
android:layout_width="fill_parent"
android:layout_height="380px"/>
</LinearLayout>
i hope you understand, if not let me know.
I'd use a RelativeLayout if I were you. Here's an example.
Make use of layout weight and for spacing just give layout margin
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1"></LinearLayout>
<LinearLayout android:id="#+id/LinearLayout02"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_weight="1" android:orientation="vertical">
<LinearLayout android:id="#+id/LinearLayout03"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_weight="1"></LinearLayout>
<LinearLayout android:id="#+id/LinearLayout04"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_weight="1"></LinearLayout>
</LinearLayout>
</LinearLayout>
I followed this example and got it worked.
Now I want to show a 'Welcome!!!' text just above the tabs in a Tabhost layout just like one show in figure
Here is my current layout file. But it does not show the Welcome message.
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top"
android:layout_gravity="top"
android:padding="5dp">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cc_welcome" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Welcome"
android:gravity="top" android:padding="50dp" android:textColor="#ffffff"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:layout_gravity="bottom"
android:paddingTop="50dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
I have edited the xml file. Have a try with this :
Updated:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="#+id/welcome"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cc_welcome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Welcome"
android:layout_centerInParent="true"
android:textColor="#ffffff"/>
</RelativeLayout>
<RelativeLayout
android:layout_below="#id/welcome"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#android:id/tabs"/>
</RelativeLayout>
</RelativeLayout>
</TabHost>
I have updated the code. Can you please try now.
You will get a better idea about the Linear and Relative layout here