Android table layout issue caused by vertical divider - android

following is my layout for Android App,
I've tried the table layout,
It will be fine if I don't add the vertical divider.
but the problems are:
the images are not right align the center, caused by my vertical divider(linear layout).
here is my sample code:
<TableLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="*"
android:layout_centerHorizontal="true"
android:id="#+id/tableexample"
android:showDividers="middle" android:divider="?android:attr/dividerVertical"
android:layout_weight="1">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tableRowContainer1"
>
<LinearLayout android:layout_width="0dp" android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_weight="1"
android:id="#+id/tableRowLayout1"
android:layout_centerHorizontal="true"
android:paddingTop="#dimen/example_list_padding"
>
<ImageButton android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/exampleImg1"
android:background="#android:color/transparent"
android:src="#drawable/reconstruct_icon01"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
android:textColor="#color/example_list_color"
android:layout_centerHorizontal="true" android:textSize="#dimen/example_font_size"
android:text="Caption1" android:layout_below="#id/exampleImg1"
/>
</LinearLayout>
<LinearLayout android:layout_width="1dp" android:layout_height="wrap_content"
android:orientation="vertical" android:minWidth="1dp"
android:gravity="center"
android:id="#+id/tableRowDivider1">
<View
style="#style/Divider"
/>
</LinearLayout>
<LinearLayout android:layout_width="0dp" android:orientation="vertical"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:paddingTop="#dimen/example_list_padding"
>
<ImageButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/exampleImg2"
android:background="#android:color/transparent"
android:src="#drawable/reconstruct_icon02"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:gravity="center_horizontal|center" android:textColor="#color/example_list_color"
android:layout_centerHorizontal="true" android:textSize="#dimen/example_font_size"
android:text="Caption2" android:layout_below="#id/exampleImg2"
/>
</LinearLayout>
</TableRow>
<TableRow>
<TextView android:background="#color/example_list_divider_color" android:layout_height="1dp"
android:layout_span="3"
/>
</TableRow>
.....
</TableLayout>
by the way, the top left one is padding programatically for testing.
if I do so, the image is right on the position, but that will cause another problem: the image will transform.
the following is what I really want.
What is the proper way to render this layout?
Thanks a lot!

i'm not sure but take a look at my layout i hope it will help you
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#android:color/darker_gray"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/myPRsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:textColor="#android:color/white"
android:text="My PRs"
/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="0.03"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/workoutsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:layout_marginTop="5dp"
android:textColor="#android:color/white"
android:gravity="center"
android:text="Workouts"
/>
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginLeft="5dp"
android:layout_weight="1"
android:background="#android:color/white" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.03"
android:background="#android:color/white" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:background="#android:color/white" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/tv3"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fontFamily="sans-serif-light"
android:textColor="#android:color/white"
android:gravity="center"
android:text="Timers"
android:layout_marginTop="5dp"/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="0.03"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/tv4"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="Statistics"
android:textColor="#android:color/white"
android:layout_marginTop="5dp"/>
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<View
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_weight="1"
android:background="#android:color/white" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.03"
android:background="#android:color/white" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_weight="1"
android:background="#android:color/white" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/tv5"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="Box Locator"
android:textColor="#android:color/white"
android:layout_marginTop="5dp"/>
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="0.03"
android:background="#android:color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/tv6"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:text="Something"
android:textColor="#android:color/white"
android:layout_marginTop="5dp"/>
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<View
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_weight="1"
android:background="#android:color/white" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.03"
android:background="#android:color/white" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_weight="1"
android:background="#android:color/white" />
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="3"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="This area is decorative image"
android:textColor="#android:color/white"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</LinearLayout>
</FrameLayout>

Go for Grid View. It's quite easy and you will achieve what you wish, also, it is supported in all screen sizes. Refer: http://developer.android.com/guide/topics/ui/layout/gridview.html

Related

RelativeLayout with layout_weight doesn't work

I have 4 LinearLayout with a layout_weight of 0.25 (each one of them uses 25% of the screen height), the first 3 LinearLayout contains an ImageView and a RelativeLayout with a layout_weight of 0.5 (they both take 50% of the LinearLayout width) and they work fine, the problem occurs on the last LinearLayout which contains 2 RelativeLayout, this is the structure:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
android:layout_weight=".25">
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/white">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/icon_news"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:layout_above="#+id/newsTextView"
/>
<TextView
android:id="#+id/newsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="News"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:textColor="#color/mainBlue"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/white">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/icon_contacts"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:layout_above="#+id/contactTextView"
/>
<TextView
android:id="#+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contatti"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:textColor="#color/mainBlue"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
</LinearLayout>
This LinearLayout doesn't work, it doesn't take the 25% height of the screen and it's just not visible.. Is it a problem with RelativeLayout with layout_weight? what should I do to fix this?
EDIT
This is the whole XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:pew="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1.0">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
android:layout_weight=".25">
<ImageView
android:layout_height="wrap_content"
android:layout_weight=".5"
android:layout_width="0dip"
android:src="#drawable/img"
android:scaleType="centerCrop"/>
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/mainBlue">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sezione 1"
android:gravity="left"
android:layout_centerInParent="true"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
android:layout_weight=".25">
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/mainBlue">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sezione 2"
android:gravity="left"
android:layout_centerInParent="true"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
<ImageView
android:layout_height="wrap_content"
android:layout_weight=".5"
android:layout_width="0dip"
android:src="#drawable/img"
android:scaleType="centerCrop"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
android:layout_weight=".25">
<ImageView
android:layout_height="wrap_content"
android:layout_weight=".5"
android:layout_width="0dip"
android:src="#drawable/img"
android:scaleType="centerCrop"/>
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/mainBlue">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sezione 1"
android:gravity="left"
android:layout_centerInParent="true"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
android:layout_weight=".25">
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/white">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/icon_news"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:layout_above="#+id/newsTextView"
/>
<TextView
android:id="#+id/newsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="News"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:textColor="#color/mainBlue"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
android:background="#color/white">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/icon_contacts"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:layout_above="#+id/contactTextView"
/>
<TextView
android:id="#+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contatti"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:textColor="#color/mainBlue"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Add Linear Layout as Root Layout with weightSum 1.
Refer this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pew="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:orientation="horizontal"
android:weightSum="1.0">
<ImageView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:scaleType="centerCrop"
android:src="#mipmap/ic_launcher" />
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#FFF">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="left"
android:text="Sezione 1"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:orientation="horizontal"
android:weightSum="1.0">
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#FFF">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="left"
android:text="Sezione 2"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:scaleType="centerCrop"
android:src="#mipmap/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:orientation="horizontal"
android:weightSum="1.0">
<ImageView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:scaleType="centerCrop"
android:src="#mipmap/ic_launcher" />
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#FFF">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="left"
android:text="Sezione 1"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.25"
android:orientation="horizontal"
android:weightSum="1.0">
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#FFF">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_above="#+id/newsTextView"
android:layout_centerHorizontal="true"
android:scaleType="centerInside"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/newsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="News"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#FFF">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_above="#+id/contactTextView"
android:layout_centerHorizontal="true"
android:scaleType="centerInside"
android:src="#mipmap/ic_launcher" />
<TextView
android:id="#+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="Contatti"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
hey I tested your code is it seems there is problem in hight you gave to each 4 child layout.
just replace
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
with
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
and do same for all 4 child views.
For reference
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:pew="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1.0" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<ImageView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:scaleType="centerCrop"
android:src="#drawable/cat1" />
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#android:color/holo_blue_bright" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="left"
android:text="Sezione 1"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#android:color/holo_blue_bright" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="left"
android:text="Sezione 2"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<ImageView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:scaleType="centerCrop"
android:src="#drawable/cat2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<ImageView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:scaleType="centerCrop"
android:src="#drawable/cat3" />
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#android:color/holo_blue_bright" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="left"
android:text="Sezione 1"
android:textColor="#fff"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".25"
android:orientation="horizontal"
android:weightSum="1.0" >
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#fff" >
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_above="#+id/newsTextView"
android:layout_centerHorizontal="true"
android:scaleType="centerInside"
android:src="#drawable/icon" />
<TextView
android:id="#+id/newsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="News"
android:textColor="#android:color/holo_blue_bright"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#fff" >
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_above="#+id/contactTextView"
android:layout_centerHorizontal="true"
android:scaleType="centerInside"
android:src="#drawable/icon" />
<TextView
android:id="#+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="10dp"
android:gravity="center_horizontal"
android:text="Contatti"
android:textColor="#android:color/holo_blue_bright"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Happy coding.
Use below code to solve this issue:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:orientation="horizontal"
android:weightSum="1.0"
android:layout_weight=".25">
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:layout_above="#+id/newsTextView"
/>
<TextView
android:id="#+id/newsTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="News"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_weight=".5"
android:layout_width="0dip"
>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:scaleType="centerInside"
android:layout_centerHorizontal="true"
android:layout_above="#+id/contactTextView"
/>
<TextView
android:id="#+id/contactTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contatti"
android:gravity="center_horizontal"
android:layout_centerInParent="true"
android:textSize="20sp"
android:textStyle="bold"
android:layout_margin="10dp"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>

Scrollview not working

This is my coding i have added a toolbar and i want the data below to scroll but its scrolling entirely.I Tried many solution in SO but still its of No use.Pls check and if found any error help me
Thanks in Advance
<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"
tools:context="com.agna.hrm_sainmarks.Address" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/White"
android:orientation="vertical" >
<include
android:id="#+id/emergencytoolbar"
layout="#layout/emergency_toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/name"
android:textSize="18dp" />
<TextView
android:id="#+id/primname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Ajith Kumar"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View01"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/relationship"
android:textSize="18dp" />
<TextView
android:id="#+id/primrelationship"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Brother"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View02"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/phone"
android:textSize="18dp" />
<TextView
android:id="#+id/primphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="9998885231"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View03"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/taddress"
android:textSize="18dp" />
<TextView
android:id="#+id/primaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="78,Muthu nagar 3rd Street,Coimbatore-44"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View04"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/Hrmbg" />
</ScrollView>
</LinearLayout>
</RelativeLayout>
emergency_toolbar
<?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.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/Hrmtool"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark"
android:titleTextColor="#color/Red" > -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:textColor="#color/Black"
android:weightSum="2"
>
<Button
android:id="#+id/pemergency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="#color/Hrmbg"
android:layout_weight="1"
android:textSize="18dp"
android:text="#string/pemergency"
android:textColor="#color/Black" />
<Button
android:id="#+id/semergency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="#color/Hrmbg"
android:layout_weight="1"
android:textSize="18dp"
android:text="#string/semergency"
android:textColor="#color/Black" />
</LinearLayout>
<!-- </android.support.v7.widget.Toolbar> -->
</RelativeLayout>
You need to do just few changes.
In emergency_toolbar.xml change the layout_height of RelativeLayout and LinearLayout to wrap_content.
In activity_main.xml put <include.... code outside LinearLayout and Inside of RelativeLayout.
You have to add LinearLayout just after ScrollView to wrap WHOLE fields as ScrollView can hold only one DIRECT CHILD.
Most important point: Add too many address field as you can see SCROLL at runtime. Just copy-paste address field and change the ids field of them.
Below is screen shot, which I have got as Outcome. And See this CodeLink.
Hope this will help.
ScrollView hold only one view as Childview try this code
<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"
tools:context="com.agna.hrm_sainmarks.Address">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/White"
android:orientation="vertical">
<include
android:id="#+id/emergencytoolbar"
layout="#layout/emergency_toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/name"
android:textSize="18dp" />
<TextView
android:id="#+id/primname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Ajith Kumar"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View01"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/relationship"
android:textSize="18dp" />
<TextView
android:id="#+id/primrelationship"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Brother"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View02"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/phone"
android:textSize="18dp" />
<TextView
android:id="#+id/primphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="9998885231"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View03"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/taddress"
android:textSize="18dp" />
<TextView
android:id="#+id/primaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="78,Muthu nagar 3rd Street,Coimbatore-44"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View04"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/Hrmbg" />
</LinearLayout>
</ScrollView>
</LinearLayout>
As Scroll View can hold only one direct child.You need to define it above Your Main Linear Layout. Also use Scroll Bars Property in Scroll View.
EDIT :
Move your Tool Bar Layout above Scroll View.
Try this code.
<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"
tools:context="com.agna.hrm_sainmarks.Address">
<include
android:id="#+id/emergencytoolbar"
layout="#layout/toolbar" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/emergencytoolbar"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/app_name"
android:textSize="18dp" />
<TextView
android:id="#+id/primname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Ajith Kumar"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View01"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/app_name"
android:textSize="18dp" />
<TextView
android:id="#+id/primrelationship"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Brother"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View02"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="phone"
android:textSize="18dp" />
<TextView
android:id="#+id/primphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="9998885231"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View03"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textSize="18dp" />
<TextView
android:id="#+id/primaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="78,Muthu nagar 3rd Street,Coimbatore-44"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View04"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#FFFFFF" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Try this, I tried to add data to it and then scrolled. The views below toolbar are being scrolled as expected:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="in.net.codestar.ratingbar.MainActivity"
tools:showIn="#layout/activity_main">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/White"
android:orientation="vertical" >
<include
android:id="#+id/emergencytoolbar"
layout="#layout/emergency_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/name"
android:textSize="18dp" />
<TextView
android:id="#+id/primname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Ajith Kumar"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View01"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/relationship"
android:textSize="18dp" />
<TextView
android:id="#+id/primrelationship"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="Brother"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View02"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/phone"
android:textSize="18dp" />
<TextView
android:id="#+id/primphone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="9998885231"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View03"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/Hrmbg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/taddress"
android:textSize="18dp" />
<TextView
android:id="#+id/primaddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="78,Muthu nagar 3rd Street,Coimbatore-4478,Muthu nagar 3rd Street,Coimbatore-44"
android:textSize="18dp" />
</LinearLayout>
<View
android:id="#+id/View04"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/Hrmbg" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
emergency_toobar.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:textColor="#color/Black"
android:weightSum="2"
>
<Button
android:id="#+id/pemergency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="#color/Hrmbg"
android:layout_weight="1"
android:textSize="18dp"
android:text="#string/pemergency"
android:textColor="#color/Black" />
<Button
android:id="#+id/semergency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="#color/Hrmbg"
android:layout_weight="1"
android:textSize="18dp"
android:text="#string/semergency"
android:textColor="#color/Black" />
</LinearLayout>
</RelativeLayout>
The following two lines solved my problem:
android:lines="4"
android:maxLines="4"
now it's working.

Google Map Inside viewpager and a vertical scroll view not getting displayed in some devices

I have a viewpager with 5 fragments and one among them is a search fragment with a google map the weired issue is that in some device the map is displayed with no problem but in some device(micromax aq 5000 Kitkat) it's not getting displayed
fragment
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/mainlayerr"
android:orientation="vertical" >
<ScrollView
android:layout_height="wrap_content"
android:layout_width="match_parent"
>
<LinearLayout
android:id="#+id/ll_MenuLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<AutoCompleteTextView
android:id="#+id/txtSearchh"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_marginLeft="#dimen/space_2_5_x"
android:layout_marginRight="#dimen/space_2_5_x"
android:layout_marginTop="#dimen/space_2_5_x"
android:hint="Search"
android:layout_gravity="bottom|left"
android:padding="5dp"
android:background="#null"
android:textColor="#color/markerboxcolor"
/>
<View
android:layout_height="1dp"
android:layout_marginTop="-6dp"
android:layout_width="match_parent"
android:layout_marginLeft="#dimen/space_2_5_x"
android:layout_marginRight="#dimen/space_2_5_x"
android:background="#color/divider_color"
/>
<RelativeLayout
android:id="#+id/search_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/tab2_wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/space_0_x"
android:layout_centerInParent="true"
android:orientation="horizontal"
android:padding="#dimen/space_2_x" >
<CheckBox
android:id="#+id/checkimage_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:contentDescription="#string/app_name"
android:text="Male"
android:layout_marginRight="5dp"
android:gravity="center|center_vertical|center_horizontal"
/>
<CheckBox
android:id="#+id/checkimage_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:text="Female"
android:layout_marginLeft="5dp"
android:contentDescription="#string/app_name"
android:gravity="center|center_vertical|center_horizontal"
/>
</LinearLayout>
</RelativeLayout>
<HorizontalScrollView
android:orientation="horizontal" android:layout_width="wrap_content"
android:id="#+id/horizontalScrolll"
android:layout_margin="10dp"
android:scrollbars="none"
android:background="#C6D7D2" android:layout_height="80dp">
<LinearLayout android:id="#+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</HorizontalScrollView>
<LinearLayout
android:id="#+id/distance_menu"
android:layout_width="match_parent"
android:layout_height="#dimen/footer_tabs_container_height"
android:layout_below="#+id/sportsViewPager"
android:baselineAligned="false"
android:gravity="center_vertical"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/tab3_wrapper"
android:layout_width="0dip"
android:layout_height="#dimen/container_height"
android:layout_gravity="center|center_horizontal|center_vertical"
android:layout_marginRight="#dimen/space_2_x"
android:layout_weight="0.15"
android:orientation="vertical" >
<TextView
android:id="#+id/distance"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="#dimen/space_2_x"
android:gravity="left|center_horizontal|center_vertical"
android:paddingLeft="#dimen/space_2_x"
android:text="#string/search_dist"
android:textColor="#color/text_color1x"
android:textSize="#dimen/text_size_medium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="#+id/tab4_wrapper"
android:layout_width="0dip"
android:layout_height="#dimen/footer_tabs_container_height"
android:layout_marginRight="#dimen/space_2_x"
android:layout_weight=".5"
android:gravity="center_vertical"
android:orientation="horizontal" >
<com.sportspartners.sportspartners.util.DiscreteSeekBar
android:id="#+id/seekBarr"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="#dimen/space_2_x"
android:paddingRight="#dimen/space_2_x"
app:dsb_allowTrackClickToDrag="false"
app:dsb_indicatorTextAppearance="#style/CustomFloaterTextAppearance"
app:dsb_progressColor="#color/my_progress_color"
app:dsb_rippleColor="#FF7788FF"
app:dsb_indicatorColor="#color/my_floater_color"
app:dsb_indicatorFormatter="%d" />
<TextView
android:id="#+id/progressID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/space_2_x"
android:layout_marginRight="#dimen/space_2_x"
android:text="10 Kms" >
</TextView>
</LinearLayout>
</LinearLayout>
<View
android:id="#+id/seprater1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/from_menu"
android:background="#color/blue" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_below="#+id/seprater1"
>
<fragment
android:id="#+id/mappy"
android:layout_width="match_parent"
android:layout_height="400dp"
android:name="com.sportspartners.sportspartners.fragments.search.SearchFragment"
class="com.google.android.gms.maps.MapFragment" />
<View
android:id="#+id/imageView123"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#android:color/transparent" />
</FrameLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<ListView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_margin="5dp"
android:divider="#null"
android:scrollbars="none"
android:id="#+id/searchhList"
android:visibility="gone"
></ListView>
<ImageView
android:id="#+id/progress_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="gone"
/>
<LinearLayout
android:layout_width="80dp"
android:layout_height="wrap_content"
android:id="#+id/messagenotificationlayout"
android:layout_alignParentRight="true"
android:visibility="gone"
android:layout_alignBottom="#+id/searchhList"
android:descendantFocusability="blocksDescendants"
>
<com.example.floatinglibrary.FloatingActionButton
android:clickable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/chatterimage"
app:fab_addButtonColorNormal="#00000000"
android:id="#+id/messagenotificationbtn"
android:background="#null"
app:fab_size="normal"
/>
<TextView
android:background="#drawable/blue_circle"
android:id="#+id/messagenotificationbadge"
android:layout_width="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:paddingRight="5dp"
android:layout_marginLeft="-17dp"
android:layout_marginTop="-20dp"
android:paddingBottom="5dp"
android:layout_height="wrap_content"
android:padding="2sp"
android:clickable="false"
android:text="10"
android:textColor="#color/white"
android:textSize="#dimen/text_size_micro_min"
/>
</LinearLayout>
</RelativeLayout>
parent layout with view pager
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/titlecontainer"
>
<LinearLayout
android:id="#+id/titlbarrSearch"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#color/markerboxcolor"
android:layout_gravity="top"
android:orientation="horizontal"
android:paddingTop="4dp"
android:visibility="gone"
android:gravity="center_vertical"
>
<ImageButton
android:layout_marginLeft="3dp"
android:id="#+id/btnsearchback"
android:src="#drawable/searchback"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:background="#null"
/>
<TextView
android:id="#+id/txttitle"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal"
android:layout_gravity="center"
android:text="Search"
android:textColor="#color/pure_white"
android:textSize="#dimen/text_size_large"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/titlbarr"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="#color/markerboxcolor"
android:layout_gravity="top"
android:weightSum="5"
android:gravity="center"
>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
>
<TextView
android:id="#+id/txt1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Feed"
android:gravity="center"
android:textColor="#color/tabred"
/>
<View
android:layout_height="4dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:background="#color/tabred"
android:id="#+id/view1"
/>
</RelativeLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
>
<TextView
android:id="#+id/txt2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Profile"
android:gravity="center"
android:textColor="#ffffff"
/>
<View
android:layout_height="4dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:background="#color/pure_white"
android:id="#+id/view2"
android:visibility="gone"
/>
</RelativeLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
>
<TextView
android:id="#+id/txt3"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Search"
android:gravity="center"
android:textColor="#ffffff"
/>
<View
android:layout_height="4dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:background="#color/pure_white"
android:id="#+id/view3"
android:visibility="gone"
/>
</RelativeLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
>
<TextView
android:id="#+id/txt4"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Followers"
android:gravity="center"
android:textColor="#ffffff"
/>
<View
android:layout_height="4dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:background="#color/pure_white"
android:id="#+id/view4"
android:visibility="gone"
/>
</RelativeLayout>
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
>
<TextView
android:id="#+id/txt5"
android:layout_width="match_parent"
android:layout_height="50dp"
android:text="Settings"
android:gravity="center"
android:textColor="#ffffff"
/>
<View
android:layout_height="4dp"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:background="#color/pure_white"
android:id="#+id/view5"
android:visibility="gone"
/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<com.sportspartners.sportspartners.util.MyViewpager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_below="#+id/titlecontainer"
android:layout_height="match_parent" >
<android.support.v4.view.PagerTabStrip
android:id="#+id/pager_headerr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/markerboxcolor"
android:layout_gravity="top"
android:visibility="gone"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#ffffff" />
</com.sportspartners.sportspartners.util.MyViewpager>
</RelativeLayout>
Finally I got the answer google map will not show up(in some devices) if it's placed inside a scroll view for that I need to set android:fillViewport="true" inside scroll view this may stop scrolling the map but will show it to a perfect size

Multiple layouts, one activity

I want to create an activity that contains 5 "FrameLayout" like the picture below.
3 equal FrameLayout in the first row and 2 FrameLayout in the second row.
I did it using Linear layouts but I got a warning that nested weights are bad. So is there an other way to make it.
Fragments should be streched on the screen without using values like (100dp).
you cal also use the two table layout..
like
<TableLayout android:weight='1'>
<TableRow>
<Linear>
<FrameLayout /> <FrameLayout /> <FrameLayout />
</Linear>
</TableRow>
</TableLayout>
<TableLayout android:weight='1'>
<TableRow>
<Linear>
<FrameLayout /> <FrameLayout/>
</Linear>
</TableRow>
</TableLayout>
its rough layout . i hope you got the idea.
Try this
<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"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#00bbff" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="1" />
</FrameLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#bb00ff" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="2" />
</FrameLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#00ff00" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="3" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#bbff00">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="4" />
</FrameLayout>
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#ffbb00" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="5" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
Try this::Hope its useful for you.
<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"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#00bbff"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="1" />
</FrameLayout>
<View android:layout_width="10dp"
android:layout_height="10dp"
/>
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#bb00ff"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="2"
/>
</FrameLayout>
<View android:layout_width="10dp"
android:layout_height="10dp"
/>
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#00ff00"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="3" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp">
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#bbff00" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="4" />
</FrameLayout>
<View android:layout_width="10dp"
android:layout_height="10dp"
/>
<FrameLayout
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#ffbb00" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="5" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
see image below ![image][1]
See This code
<?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"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="2dp"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="2dp"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="1"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_marginTop="2dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="150dp"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"/>
</LinearLayout>
<LinearLayout
android:layout_width="150dp"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:gravity="center"
android:layout_marginLeft="1dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />
</LinearLayout>
</LinearLayout>

Android how to proper overlay image to support multiple screen

I was able to overlay an image in the table layout, but the design will be run in multiple size of screen. Because i'm using margin to achieve the effect of overlay. Below is the code. Is there any suggestion that i can achieve the desired result? Thanks.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="0.7"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:background="#drawable/ads_body"
android:stretchColumns="*">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.10"
android:gravity="center"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/button"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="260dp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="50dp">
</View>
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="0.20"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/scoreboard_avatar_how_to_earn_point"
android:textColor="#color/dark_grey"
android:textStyle="bold" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_weight="0.20"
android:gravity="center">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/scoreboard_avatar_how_to_earn_point"
android:textColor="#color/dark_grey" />
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.1">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_weight="0.5"
android:background="#drawable/ads_table_border"
android:paddingTop="5dp">
<ImageView
android:id="#+id/scoreboard_point"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:src="#drawable/scoreboard_point" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="#drawable/ads_table_border"
android:paddingTop="5dp">
<TextView
android:id="#+id/ads_point"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/scoreboard_point"
android:textColor="#color/dark_grey"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="#drawable/ads_table_border"
android:paddingTop="5dp">
<ImageView
android:id="#+id/scoreboard_coin"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:src="#drawable/dibs_scoreboard_coin" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="0.5"
android:background="#drawable/ads_table_border"
android:paddingTop="5dp">
<TextView
android:id="#+id/ads_coin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="#string/scoreboard_coin"
android:textColor="#color/dark_grey"
android:textStyle="bold" />
</RelativeLayout>
</TableRow>
</TableLayout>
</RelativeLayout>
</FrameLayout>
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:layout_marginTop="-150dp"
android:adjustViewBounds="true"
android:background="#drawable/head_female_1_circle"
android:scaleType="fitCenter" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.30"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp">
<ImageView
android:id="#+id/ifc_reward"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:background="#drawable/hero_chamber_city_line"
android:contentDescription="#string/app_name" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:id="#+id/btnView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp"
android:layout_marginLeft="25dp"
android:layout_marginRight="25dp"
android:background="#drawable/ads_button" />
</LinearLayout>
Create folders and xml files for different screen sizes:
See: http://developer.android.com/guide/practices/screens_support.html
If that doesn't help try getting screen size from Java code and then setting margins programatically.

Categories

Resources