Text overlapping in Android text view - android

I am facing a strange behavior of text view. When the text view has multiple lines, the lines are overlapping on each other. I tried to solve it but didn't get any clue yet.
Here is the XML:
<?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="fill_parent"
android:background="#drawable/googletv_bkgd_no_title"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="85dip"
android:gravity="center_vertical"
android:orientation="horizontal" >
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="fill_parent"
android:layout_height="match_parent" android:paddingRight="50dip">
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="right|center_vertical" android:gravity="center_vertical">
<TextView
android:id="#+id/navigationHeaderTxtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#cccccc"
android:visibility="gone" android:layout_gravity="center_vertical"/>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" android:layout_gravity="left|center_vertical" android:layout_marginLeft="5dip" android:textColor="#ebebee" android:textStyle="bold"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<!--
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_gravity="top|right" android:layout_marginRight="20dip">
<Button
android:id="#+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:background="#drawable/btn_back" />
<Button
android:id="#+id/btnHome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:background="#drawable/btn_home" />
</LinearLayout>-->
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_gravity="top" android:layout_marginTop="20dip" android:gravity="center">
<ImageView
android:id="#+id/arrow_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow_up" android:visibility="visible"/>
</LinearLayout>
<FrameLayout
android:id="#+id/frameLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:paddingLeft="80dip" android:paddingRight="80dip">
<GridView
android:id="#+id/gridView1"
android:layout_width="match_parent"
android:layout_height="250dip"
android:cacheColorHint="#00000000"
android:horizontalSpacing="10dip"
android:listSelector="#drawable/list_selector"
android:numColumns="5"
android:padding="10dip"
android:verticalSpacing="10dip" >
</GridView>
</FrameLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:layout_gravity="top" android:layout_marginTop="20dip" android:gravity="center">
<ImageView
android:id="#+id/arrow_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/arrow_down" android:visibility="visible"/>
</LinearLayout>
<LinearLayout
android:id="#+id/frameLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/title_color"
android:textSize="25dip" android:layout_gravity="center_horizontal"/>
<TextView
android:id="#+id/textDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
I have attached a screenshot regarding the problem.
How do I fix this?

You will need to adjust your line spacing to accommodate the odd custom font, such as android:lineSpacingExtra on your TextView.

Related

Centering a linearlayout present inside a listview

I have a listview which contains a linearlayout. I am trying to get the linearlayout to the center of the screen(horizontally) but it doesn't work.
How it looks -
Portrait -
Landscape -
I want the linearlayout(which has the text "text" and the two images) to come to the center of the screen(horizontally) in both the orientations.
I've tried using layout_gravity on the linearlayout but it doesn't work.
Here's my code -
<?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="match_parent"
android:orientation="vertical"
android:background="#EEEEEE" >
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/parentListContainer">
</ListView>
</LinearLayout>
Each listview item -
<?xml version="1.0" encoding="utf-8"?>
<!-- I want this layout centered. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textColor="#000000"
android:text="text"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/ivBottle1"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvBottle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textSize="22sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/ivBottle2"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvBottle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textSize="22sp" >
</TextView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Please help.
EDIT: Neither gravity="center" works on the listview, nor does layout_gravity="center" on the linearlayout.
<?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="match_parent"
android:orientation="vertical"
android:background="#EEEEEE" >
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="#+id/parentListContainer">
</ListView>
</LinearLayout>
See here for explanation : https://stackoverflow.com/a/3482757/4706693
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textColor="#000000"
android:text="text"/>
<LinearLayout
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/ivBottle1"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvBottle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textSize="22sp" >
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/ivBottle2"
android:scaleType="fitXY"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="true"/>
<TextView
android:id="#+id/tvBottle2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="top|center"
android:text="vino"
android:textSize="22sp" >
</TextView>
</LinearLayout>
</LinearLayout>

designing with linear layout in android

I want to design following design in android using Linear layout
I had written following code but not working
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_weight="1"
android:layout_height="fill_parent" android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_weight="1" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/alert_dark_frame" />
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentLeft="true"
android:text="TextView" android:layout_weight="1" />
<TextView
android:id="#+id/textView2" android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true"
android:text="TextView" />
</LinearLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" android:hint="TestData"/>
</LinearLayout>
</LinearLayout>
it gives me output like
can anyone pointout me.. where is problem???
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/alert_dark_frame" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="dfasdfasdfasfasf" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:text="07 DEc" />
</LinearLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dskfhasjkldfhadjklsfhadjklsfhajkldfhadjklsfhajklsfhajklsdfhajklsdfhajklsdfhajkldf" />
</LinearLayout>
</LinearLayout>
This will work... :)
This will work for you.
<?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="#ffffff"
android:padding="5dip" >
<ImageView
android:id="#+id/icon"
android:layout_width="70px"
android:layout_height="50px"
android:layout_marginRight="3dip"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/toptext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:text="dsggsdggfsgf"
android:textColor="#000000"
android:textSize="16px"
android:textStyle="bold" />
<TextView
android:id="#+id/datetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:maxLines="1"
android:text="1 dec 2012"
android:textColor="#cccccc"
android:textSize="12px"
android:textStyle="bold" />
</RelativeLayout>
<TextView
android:id="#+id/bottomtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="dsggsdggfsgfwaffgdgafgggfdgfdgsfgfdgdfsgdfdsggsdggfsgfwaffgdgafgggfdgfdgsfgfdgdfsgdfdsggsdggfsgfwaffgdgafgggfdgfdgsfgfdgdfsgdfdsggsdggfsgfwaffgdgafgggfdgfdgsfgfdgdfsgdf"
android:textColor="#696969"
android:textSize="12px" />
</LinearLayout>
</LinearLayout>
I think you can use relativelayout at first level, like the following:
<relativelayout>
<imageview align to parent top, left, bottom>
<linearlayout align to parent to, right, right to image view>
<textview1/>
<textview2/>
</linearlayout>
<textview align to parent bottom, right, righto to image view, below linearlayout>
</relativelayout>
This should work. But it will be better if you use 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="wrap_content"
android:layout_weight="1"
android:background="#android:color/white"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/alert_dark_frame" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="2" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView" />
</LinearLayout>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="TestData"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_weight="1"
android:layout_height="fill_parent" android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="3"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#android:drawable/alert_dark_frame"
android:layout_weight="2"/>
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="hfdfhfj" android:layout_weight="2" />
<TextView
android:id="#+id/textView2" android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6 Dec 2012" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fkjfkdsnfdsnfkdsn\nmnfkfknfkdf\nfknf" android:hint="TestData"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Try this code.it is exactly what you want.

android tablelayout with complex component placement

EDITED: I HAVE FOUND THE SOLUTION MYSELF. THANK YOU!
I want to create the following screen for an Android App:
Right now I have this:
with this code:
<?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="horizontal"
android:weightSum="1" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight=".65"
android:weightSum="5" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TOURNAMENT: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp"/>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="GAME: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="BEST OF: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="BRACKET STYLE: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight=".35"
android:weightSum="5" >
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp" />
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp" />
<RelativeLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:text="CANCEL" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/button2"
android:text="CREATE" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
The text can be aligned to the right using android:gravity="right", but how can I make it
centered vertically?
--> AISHH, it's: android:gravity="center_vertical|right"
Thank you!!
Well TableLayout is not a good ideea. You should try using a RelativeLayout and some LinearLayout nested inside.
Try something like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:id="#+id/first_linear"
android:orientation="vertical">
<!-- Note that for text view,and editText you might need to use certain values (dip values) cuz wrap content will try to arrange the view -->
<TextView
android:id="#+id/first_text_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id = "#+id/first_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<!-- we align all the following linearlayouts below the first -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/first_linear"
android:id="#+id/second_linear"
android:orientation="vertical">
<TextView
android:id="#+id/second_text_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id = "#+id/second_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<!-- add all the layouts like those from above -->
<!-- ...... -->
<!-- after you added all the fields you can add a linear layout containing two buttons to float below the last one -->
I've done a similar layout like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_height="fill_parent" android:layout_width="fill_parent"
>
<ScrollView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1.0">
<LinearLayout android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="fill_parent">
<TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:stretchColumns="1" android:shrinkColumns="1">
<TableRow android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:text="Value1" android:gravity="right" />
<EditText android:singleLine="true" android:id="#+id/editTextVal1" />
</TableRow>
<TableRow android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:text="Long name value2" android:gravity="right" />
<EditText android:singleLine="true" android:id="#+id/editTextVal1" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
<LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Save" />
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Cancel" />
</LinearLayout>
</LinearLayout>
There's a scroll panel in there to have the buttons on the bottom of the screen at all times, in case your configuration goes longer.
So this is the implementation I came up with. Not the best but worked for me :)
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight=".65"
android:weightSum="5"
android:paddingTop="10dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="TOURNAMENT: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|right"/>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="GAME: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|right"/>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="BEST OF: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|right"/>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="BRACKET STYLE: "
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|right"/>
<!-- fill up the space so that the components on top are displayed correctly -->
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:gravity="center_vertical|right"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight=".35"
android:weightSum="5"
android:paddingTop="10dp" >
<EditText
android:id="#+id/tourName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:gravity="center_vertical|left" />
<Spinner
android:id="#+id/spinGameName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:gravity="center_vertical|left" />
<Spinner
android:id="#+id/spinBestOf"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:gravity="center_vertical|left" />
<Spinner
android:id="#+id/spinBracketType"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="10dp"
android:gravity="center_vertical|left" />
<RelativeLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1" >
<Button
android:id="#+id/btnCancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:text="CANCEL" />
<Button
android:id="#+id/btnCreate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="#+id/btnCancel"
android:text="CREATE" />
</RelativeLayout>
</LinearLayout>

Android Layout not displaying properly

I have a layout problem, the idea is that the buttons and text dont show
<?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="#ffffff" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#5094c5"
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingTop="8dp" >
<ImageView
android:id="#+id/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/logo" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:adjustViewBounds="true"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical" >
<ImageButton
android:id="#+id/buton_produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon" />
<TextView
android:id="#+id/produse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Produse"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
Set the height and width in the xml layout file to what they should be when they are visible but initially, in code, get a reference to them and make them invisible. Then, when needed, you can make them visible (in code).
Maybe better try with RelativeLayout. This seems to be too nested and too much complicated than it suppose to be.
You can give setVisibility() property to button and textview in layout.

How to set the header and footer for linear layout in android

Can anybody tell me how to set a fixed header and footer for relative layout and center point? I want to add scrollable and adding array of webview dynamically when I want to scroll center point only scrollable in android. Can anybody give an example?
I tried but center part webview is not appearing properly, is there anything to change?
my xml code is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="#+id/mainrelativelayout" android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="#+id/linear1" android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView android:paddingRight="75dip" android:paddingLeft="20dip" android:text="Index" android:id="#+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#color/black" android:textStyle="bold"></TextView>
<TextView android:paddingRight="60dip" android:text="Last" android:id="#+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#color/black" android:textStyle="bold"></TextView>
<TextView android:text="Change" android:id="#+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#color/black" android:textStyle="bold"></TextView>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="#+id/linear1" android:layout_height="6dip"
android:orientation="horizontal"
>
<ImageView android:id="#+id/ImageView08" android:layout_gravity="center" android:background="#drawable/line" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageView>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linear2"
android:orientation="horizontal"
>
<ImageView android:id="#+id/ImageView05" android:paddingTop="5dip" android:layout_gravity="center" android:background="#drawable/down" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<TextView android:paddingRight="30dip" android:paddingLeft="10dip" android:text="" android:id="#+id/txtindex0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#color/black" android:textSize="12dip"></TextView>
<TextView android:paddingRight="55dip" android:text="" android:id="#+id/txtlast0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#color/black" android:textSize="12dip"></TextView>
<TextView android:text="" android:id="#+id/txtchange0" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12dip" android:textColor="#color/red1"></TextView>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linear3"
android:orientation="horizontal"
>
<ImageView android:id="#+id/ImageView02" android:layout_gravity="center" android:background="#drawable/up" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<TextView android:paddingRight="46dip" android:paddingLeft="10dip" android:text="" android:id="#+id/txtindex1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#color/black" android:textSize="12dip"></TextView>
<TextView android:paddingRight="64dip" android:text="" android:id="#+id/txtlast1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#color/black" android:textSize="12dip"></TextView>
<TextView android:text="" android:id="#+id/txtchange1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12dip" android:textColor="#color/green1"></TextView>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linear4"
android:orientation="horizontal"
>
<ImageView android:id="#+id/ImageView03" android:layout_gravity="center" android:background="#drawable/up" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<TextView android:paddingRight="69dip" android:paddingLeft="10dip" android:text="" android:id="#+id/txtindex2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#color/black" android:textSize="12dip"></TextView>
<TextView android:paddingRight="67dip" android:text="" android:id="#+id/txtlast2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#color/black" android:textSize="12dip"></TextView>
<TextView android:text="" android:id="#+id/txtchange2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12dip" android:textColor="#color/green1"></TextView>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/linear4"
android:orientation="horizontal"
>
<ImageView android:id="#+id/ImageView04" android:layout_gravity="center" android:background="#drawable/up" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<TextView android:paddingRight="61dip" android:paddingLeft="10dip" android:text="" android:id="#+id/txtindex3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#color/black" android:textSize="12dip"></TextView>
<TextView android:paddingRight="65dip" android:text="" android:id="#+id/txtlast3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#color/black" android:textSize="12dip"></TextView>
<TextView android:text="" android:id="#+id/txtchange3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12dip" android:textColor="#color/green1"></TextView>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="#+id/linear1" android:layout_height="4dip"
android:orientation="horizontal"
>
<ImageView android:id="#+id/ImageView08" android:layout_gravity="center" android:background="#drawable/line" android:layout_width="fill_parent" android:layout_height="wrap_content"></ImageView>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="15dip"
android:id="#+id/linear5"
android:orientation="horizontal"
>
<TextView android:text="Market data delayed at least 15 minutes " android:id="#+id/TextView16" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12dip" android:textColor="#color/gray2"></TextView>
</LinearLayout>
</LinearLayout>
<------ finishing header-------->
<---------- adding footer----------->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/imglinear"
android:background="#color/white"
android:layout_alignParentBottom="true"
>
<ImageView android:id="#+id/ImageView15" android:src="#drawable/quest_i" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</LinearLayout>
<--------------finishing footer------->
<------------ center point of screen--------->
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/white"
android:id="#+id/mainlinear3"
android:layout_above="#+id/imglinear"
android:layout_below="#+id/mainlinear2"
>
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#color/white"
android:id="#+id/relative3">
</RelativeLayout>
</ScrollView>
</RelativeLayout>
<-----------center point finishing---------->
</RelativeLayout>
thanks
<?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">
<!-- HEADER -->
<include android:id="#+id/top_header"
android:layout_alignParentTop="true" layout="#layout/layout_header" />
<!-- FOOTER -->
<LinearLayout android:id="#+id/bottom_menu"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:layout_alignParentBottom="true">
<!-- menu bar -->
<include layout="#layout/layout_footer_menu" />
</LinearLayout>
<!-- MAIN PART -->
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:layout_below="#id/top_header" android:layout_above="#id/bottom_menu"
android:layout_weight="1"
android:id="#+id/sub_content_view"
android:paddingBottom="5sp" android:background="#EAEAEA">
</LinearLayout>
</RelativeLayout>
It is better to set to MAIN PART both:
android:layout_below="#id/top_header"
android:layout_above="#id/bottom_menu"
In your case content will be under the footer and scroll bar will be shown incorrect.
Also you need place footer in code above content - android want see ID's (#id/bottom_menu) if it wasn't define before.

Categories

Resources