I need set textView10 at center of vertical and horizontal. I've tried a lot without results... I tried with gravity options but nothing.. any idea? textView10 is within scrollview. Thanks for help.
<?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="#000000"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="151dp"
android:layout_height="fill_parent"
android:textSize="15pt" />
<ScrollView
android:id="#+id/scrollView10"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#000000" >
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="#ffffff"
android:textSize="13sp"
android:textStyle="italic" />
</ScrollView>
</LinearLayout>
<Button
android:id="#+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chiudi" />
</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="fill_parent"
android:background="#000000"
android:orientation="vertical" >
<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:orientation="horizontal" >
<TextView
android:layout_width="151dp"
android:layout_height="fill_parent"
android:textSize="15pt" />
<ScrollView
android:id="#+id/scrollView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#000000" >
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="320dp"
android:background="#000000"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="13sp"
android:text="Hi What is your name"
android:textStyle="italic" />
</ScrollView>
</LinearLayout>
<Button
android:id="#+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chiudi" />
Change your outer layout to RelativeLayout and position yout ScrollView at the parent center. Position other elements in relation to one in center
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal" >
<TextView
android:id="#+id/TextView1"
android:layout_width="151dp"
android:layout_height="fill_parent"
android:textSize="15pt" />
<ScrollView
android:id="#+id/scrollView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#000000" >
<TextView
android:id="#+id/textView10"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:gravity="center_vertical"
android:textAlignment="center"
android:textColor="#ffffff"
android:textSize="13sp"
android:textStyle="italic" />
</ScrollView>
</RelativeLayout>
Put the TextView inside of a RelativeLayout, and put that RelativeLayout inside of the ScrollView.
Then, set android:layout_centerInParent="true" within the TextView
Related
I have a simple LinerLayout with 3 child linear layouts , each have a text view
when Im trying to align the text view to the center or to the right , nothing happens. its always aligned to the left, why ?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_weight="1"
android:id="#+id/alert_type"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="TYPE"/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_below="#id/alert_type"
android:id="#+id/alert_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/alert_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="ALERT"/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:layout_below="#id/alert_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/alert_details"
android:text="DETAILS" />
</LinearLayout>
</LinearLayout>
you can use RelativeLayout instead
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_weight="1"
android:id="#+id/alert_type"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="TYPE"/>
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_below="#id/alert_type"
android:id="#+id/alert_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/alert_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="ALERT"/>
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_below="#id/alert_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/alert_details"
android:text="DETAILS" />
</RelativeLayout>
</LinearLayout>
or you can use gravity to the linearlayout not textview..like
<LinearLayout
android:layout_weight="1"
android:id="#+id/alert_type"
android:gravity="right"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TYPE"/>
</LinearLayout>
Change android:layout_width="wrap_content" of TextView to match_parent
Set gravity like
android:gravity="center"
You need to set
android:gravity="center"
for each TextView's and LinearLayout.
change layout_width="wrap_content" and layout_gravity="centre"
<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:id="#+id/alert_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1" >
<TextView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="TYPE" />
</LinearLayout>
<LinearLayout
android:id="#+id/alert_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/alert_type"
android:layout_gravity="center"
android:layout_weight="1" >
<TextView
android:id="#+id/alert_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="ALERT" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/alert_layout"
android:layout_gravity="center"
android:layout_weight="1" >
<TextView
android:id="#+id/alert_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DETAILS" />
</LinearLayout>
Use below XML code for your layout, in which I set all textview at center position
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/alert_type"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:id="#+id/type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TYPE" />
</LinearLayout>
<LinearLayout
android:id="#+id/alert_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:id="#+id/alert_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="ALERT" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
android:id="#+id/alert_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DETAILS" />
</LinearLayout>
</LinearLayout>
You just need to add android:gravity="center" in your linear layout. You can also provide any alignment like right, center_vertical etc.
I need set a textview (with its background) that fill half screen of device with fixed size of background. I try this code but I can't. The goal is: half screen, up I show image, down a textview.
<?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="#000000"
android:orientation="vertical" >
<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:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/luna"
android:textSize="15pt" />
<ScrollView
android:id="#+id/scrollView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#000000" >
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="320dp"
android:background="#000000"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="14sp"
android:text="jjkjkljkjkldjklsdfjkljklsdfjklsdfjklsdfjklsdfjklsdfjklsdfjklfjlsdfjkl"
android:autoLink="web|email"
android:textStyle="italic" />
</ScrollView>
</LinearLayout>
<Button
android:id="#+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chiudi" />
</LinearLayout>
you can achieve this by adding weights.
<?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="#000000"
android:orientation="vertical" >
<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:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/luna"
android:textSize="15pt"
android:layout_weight="1"/>
<ScrollView
android:id="#+id/scrollView10"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#000000"
android:layout_weight="1" >
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="320dp"
android:background="#000000"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="14sp"
android:text="jjkjkljkjkldjklsdfjkljklsdfjklsdfjklsdfjklsdfjklsdfjklsdfjklfjlsdfjkl"
android:autoLink="web|email"
android:textStyle="italic" />
</ScrollView>
</LinearLayout>
<Button
android:id="#+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chiudi" />
</LinearLayout>
Check this:
I have changed the inner linear layout to relative layout. I think it will give result as you want:
<?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="#000000"
android:orientation="vertical" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:background="#000000" >
<TextView
android:id="#+id/textView10"
android:layout_width="match_parent"
android:layout_height="320dp"
android:autoLink="web|email"
android:background="#000000"
android:gravity="center"
android:text="jjkjkljkjkldjklsdfjkljklsdfjklsdfjklsdfjklsdfjklsdfjklsdfjklfjlsdfjkl"
android:textColor="#ffffff"
android:textSize="14sp"
android:textStyle="italic" />
</ScrollView>
<ImageView
android:id="#+id/img"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/scrollView10"
android:background="#drawable/luna"
android:textSize="15pt" />
</RelativeLayout>
<Button
android:id="#+id/button10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Chiudi" />
</LinearLayout>
I have defined scrollview first. And then I defined ImageView with match_parent sizes. So it takes up all remaining space of screen. This way, image proportion will also be proper. Hope it helps.
I have a layout as below
<LinearLayout>
<RelativeLayout>
</RelativeLayout>
<ScrollView>
<LinearLayout>
<LinearLayout>
</ScrollView>
</LinearLayout>
this is to divide the screen into half showing graph at one half of the screen and the report at the other half which alone i wish to be scrollable.
UPDATE
Please find the xml as below
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android=""
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#888888" />
<LinearLayout
android:id=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:layout_marginBottom="10sp"
android:orientation="vertical">
<TextView
android:id=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor=""
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor=""
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#888888"
android:orientation="vertical" />
<LinearLayout
android:id=""
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible"
android:orientation="horizontal">
<RelativeLayout
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_gravity="left"
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:orientation="vertical">
<TextView
android:id="#+id/course_status"
android:layout_alignParentLeft="true"
android:textColor="#000000"
android:textSize="14sp"
android:paddingLeft="10dp"
android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="50dp"/>
<ImageView
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src=""
android:id=""
android:layout_marginTop="50dp" />
<edu.apollogrp.android.widget.ProgressCircle
android:id=""
android:layout_width="170dp"
android:layout_height="170dp"
android:indeterminateOnly="false"
android:layout_centerInParent="true"
android:progressDrawable=""
android:layout_marginTop="50dp"
/>
<ImageView
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src=""
android:id=""
android:layout_marginTop="50dp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignRight=""
android:layout_alignWithParentIfMissing="true"
android:layout_centerVertical="true"
android:addStatesFromChildren="false"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="#
android:textColor="#color/grades_green"
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<TextView
android:id="#
android:textColor=""
android:textSize="20sp"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"> </TextView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:layout_marginLeft="40dp" >
<TextView
android:id="#
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#color/grades_green"
android:textSize="12sp"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="9sp"
android:textStyle="bold" >
</TextView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:background="#888888"
android:orientation="horizontal" />
<ScrollView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:fillViewport="false"
>
<LinearLayout
android:id="#
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content"
>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
but the whole layout is scrollable now :(
Is there any way i can make only half the screen scrollable?
PS: android:fillViewport is set to false
UPDATE
I found out why the scroll is not working. it was because the scroll was inside a pull to refresh list view. :(
Looking for a work around for that now
Use layout_weight, here is sample code
<LinearLayout>
<RelativeLayout android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
</RelativeLayout>
<ScrollView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<LinearLayout>
<LinearLayout>
</ScrollView>
</LinearLayout>
try to put the layout_weight attribute to divide the screen.
<LinearLayout>
<RelativeLayout android:layout_weight="1">
</RelativeLayout>
<ScrollView android:layout_weight="1">
<LinearLayout>
<LinearLayout>
</ScrollView>
</LinearLayout>
you can try this:
<?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:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parentt"
android:layout_marginLeft="5dp"
android:background="#ffff"
android:layout_weight="1">
////// Your left side layout content /////////
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:background="#ffff"
android:orientation="vertical"
android:layout_weight="1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content"
>
<TextView
android:id=""
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
The scroll view was not working because it was inside a list view that implements the pull to refresh.. Hence the layout changes dont effect.
Sorry everyone, thanks a bunch for the help.
I have a layout with a view text views, a table and then some buttons at the bottom.
I wanted the buttons to always be at the bottom regardless of the height of the table so I changed the layout to relative so I could do this.
However this mashed all the textviews and the table into one line. So I put these in a LinearLayout within the RelativeLayout which I thought would fix the problem. Problem now is that only the first TextView and the buttons at the bottom show up. Everything else is missing.
Here is the xml code I am using to define this layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="4dip"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<TextView
android:id="#+id/view_meal_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Spaghetti Bolognaise"
android:textSize="25sp" />
<TextView
android:id="#+id/view_meal_type"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Dinner"
android:textSize="16sp" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/view_day_calories"
android:text="#string/calories_label"
android:textSize="18sp" />
<TextView
android:id="#+id/view_day_calories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="#string/calories_today_value"
android:textSize="18sp" />
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="10dip"
android:background="#color/hr" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:stretchColumns="0,1,2" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/meal_table_ingred_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ingredient"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/meal_table_quantity_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/quantity"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/meal_table_calories_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/calories"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:weightSum="1.0" >
<Button
android:id="#+id/edit_meal_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/edit_meal_label" />
<Button
android:id="#+id/favourite_meal_button"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="#string/favourite_meal_label" />
</LinearLayout>
</RelativeLayout>
Thanks for your help!
Change
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
to
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
I want to place a textview on the right of a layout and on the left of a layout, but they keep stacking ontop of each other:
<LinearLayout
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent" android:orientation="horizontal">
<TextView
android:id="#+id/lefttext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:text="Symbol"/>
<TextView
android:id="#+id/righttext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:text="Price"/>
</LinearLayout>
Try this:
<?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"
>
<TextView
android:id="#+id/left_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Symbol"
/>
<TextView
android:id="#+id/right_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Price"
/>
</LinearLayout>
Why are you specifying 0dip for the height on these?
For symbols on sides:
<?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"
>
<TextView
android:id="#+id/left_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dip"
android:gravity="left"
android:text="Symbol"
/>
<TextView
android:id="#+id/right_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dip"
android:gravity="right"
android:text="Price"
/>
</LinearLayout>
And done with a RelativeLayout:
<?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"
>
<TextView
android:id="#+id/left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip"
android:layout_alignParentLeft="true"
android:text="Code"
/>
<TextView
android:id="#+id/right_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:layout_toRightOf="#+id/left_text"
android:gravity="right"
android:text="Company Name"
/>
</RelativeLayout>
With LinearLayout, just put an empty TextView with the weight between them:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/lefttext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Symbol"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<TextView
android:id="#+id/righttext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Price"/>
</LinearLayout>
Use android:layout_alignParentLeft="true" and android:layout_alignParentRight="true" on view inside RelaytiveLayout like this
<?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="wrap_content"
>
<TextView
android:id="#+id/left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left|center_vertical"
android:text="Symbol"
/>
<TextView
android:id="#+id/right_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="right|center_vertical"
android:text="Price"
/>
</RelativeLayout>
Alternatively you can use TableLayout with stretchColumn set to stretch the second column to the size of parent.