spinner expanding beyond screen bounds - android

I have a layout that contains a TableLayout with three rows. Each row has a TextView and a Spinner. The Spinners' column is set to stretch. My problem is that the Spinners are stretching off the edge of the screen when they contain a long string. I would like them to truncate the string instead. Here's a screenshot of the problem:
http://www.comicfanboy.net/images/screenshot.png
and here's the xml for the layout:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/settings_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:paddingLeft="3dp" android:paddingRight="3dp">
<TextView android:id="#+id/textView1" android:layout_height="wrap_content" android:text="#string/general_information_defaults" android:gravity="center_horizontal" android:layout_width="fill_parent"></TextView>
<TableLayout android:layout_height="wrap_content" android:id="#+id/tableLayout1" android:layout_width="fill_parent" android:stretchColumns="1">
<TableRow android:id="#+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="#+id/textView2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="right|center_vertical" android:text="Spinner Label 1"></TextView>
<Spinner android:layout_height="wrap_content" android:id="#+id/default_organization_spinner" android:layout_width="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="#+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="#+id/TextView01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="right|center_vertical" android:text="Spinner Label 2"></TextView>
<Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/default_sport_spinner"></Spinner>
</TableRow>
<TableRow android:id="#+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="#+id/TextView02" android:gravity="right|center_vertical" android:layout_height="fill_parent" android:layout_width="fill_parent" android:text="Spinner Label 3"></TextView>
<Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/default_injury_spinner"></Spinner>
</TableRow>
</TableLayout>
<TextView android:layout_width="fill_parent" android:id="#+id/TextView03" android:gravity="center_horizontal" android:layout_height="wrap_content" android:text="#string/email_defaults" android:paddingTop="20dp"></TextView>
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/TableLayout01" android:stretchColumns="1">
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/TableRow02">
<TextView android:layout_height="fill_parent" android:id="#+id/TextView04" android:gravity="right|center_vertical" android:layout_width="fill_parent" android:text="#string/to"></TextView>
<EditText android:inputType="textEmailAddress" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/default_to_field">
<requestFocus></requestFocus>
</EditText>
</TableRow>
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/TableRow01">
<TextView android:layout_height="fill_parent" android:id="#+id/TextView06" android:gravity="right|center_vertical" android:layout_width="fill_parent" android:text="#string/cc"></TextView>
<EditText android:inputType="textEmailAddress" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/default_cc_field"></EditText>
</TableRow>
</TableLayout>
<TextView android:layout_width="fill_parent" android:id="#+id/TextView05" android:gravity="center_horizontal" android:layout_height="wrap_content" android:text="#string/program_options" android:paddingTop="20dp"></TextView>
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingLeft="40dp" android:id="#+id/auto_sync_checkbox" android:text="#string/auto_sync_at_login"></CheckBox>
</LinearLayout>
</ScrollView>

For the spinner:
android:layout_weight="1"
This helped me.

android:layout_width="100dip" Use this tag in the spinner.

Related

Android Spinner width in TableRow is constant [duplicate]

I have a layout that contains a TableLayout with three rows. Each row has a TextView and a Spinner. The Spinners' column is set to stretch. My problem is that the Spinners are stretching off the edge of the screen when they contain a long string. I would like them to truncate the string instead. Here's a screenshot of the problem:
http://www.comicfanboy.net/images/screenshot.png
and here's the xml for the layout:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/settings_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_horizontal">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:paddingLeft="3dp" android:paddingRight="3dp">
<TextView android:id="#+id/textView1" android:layout_height="wrap_content" android:text="#string/general_information_defaults" android:gravity="center_horizontal" android:layout_width="fill_parent"></TextView>
<TableLayout android:layout_height="wrap_content" android:id="#+id/tableLayout1" android:layout_width="fill_parent" android:stretchColumns="1">
<TableRow android:id="#+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="#+id/textView2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="right|center_vertical" android:text="Spinner Label 1"></TextView>
<Spinner android:layout_height="wrap_content" android:id="#+id/default_organization_spinner" android:layout_width="wrap_content"></Spinner>
</TableRow>
<TableRow android:id="#+id/tableRow2" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="#+id/TextView01" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="right|center_vertical" android:text="Spinner Label 2"></TextView>
<Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/default_sport_spinner"></Spinner>
</TableRow>
<TableRow android:id="#+id/tableRow3" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="#+id/TextView02" android:gravity="right|center_vertical" android:layout_height="fill_parent" android:layout_width="fill_parent" android:text="Spinner Label 3"></TextView>
<Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/default_injury_spinner"></Spinner>
</TableRow>
</TableLayout>
<TextView android:layout_width="fill_parent" android:id="#+id/TextView03" android:gravity="center_horizontal" android:layout_height="wrap_content" android:text="#string/email_defaults" android:paddingTop="20dp"></TextView>
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/TableLayout01" android:stretchColumns="1">
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/TableRow02">
<TextView android:layout_height="fill_parent" android:id="#+id/TextView04" android:gravity="right|center_vertical" android:layout_width="fill_parent" android:text="#string/to"></TextView>
<EditText android:inputType="textEmailAddress" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/default_to_field">
<requestFocus></requestFocus>
</EditText>
</TableRow>
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="#+id/TableRow01">
<TextView android:layout_height="fill_parent" android:id="#+id/TextView06" android:gravity="right|center_vertical" android:layout_width="fill_parent" android:text="#string/cc"></TextView>
<EditText android:inputType="textEmailAddress" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="#+id/default_cc_field"></EditText>
</TableRow>
</TableLayout>
<TextView android:layout_width="fill_parent" android:id="#+id/TextView05" android:gravity="center_horizontal" android:layout_height="wrap_content" android:text="#string/program_options" android:paddingTop="20dp"></TextView>
<CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingLeft="40dp" android:id="#+id/auto_sync_checkbox" android:text="#string/auto_sync_at_login"></CheckBox>
</LinearLayout>
</ScrollView>
For the spinner:
android:layout_weight="1"
This helped me.
android:layout_width="100dip" Use this tag in the spinner.

Long text in TextView

I want to display a long text in a TextView. This is my XML:
<TableLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:text="#string/text" />
<TextView
android:id="#+id/gender"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:text="#string/lorem" />
</TableRow>
</TableLayout>
And this is how it looks like:
The long text doesn't fit. What do I have to change?
<TableLayout
android:layout_width="fill_parent"
android:layout_height="100dip"
android:layout_weight="1" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:padding="5dip"
android:text="#string/text" />
<TextView
android:id="#+id/gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="right"
android:text="#string/lorem" />
</TableRow>
</TableLayout>
Depends on the style, that you want to achive: If Its okay to have multible-Lines you can just add in xml
android:singleLine="false"
or
android:lines="2"
If not you can allow to scroll it horizontally with
android:scrollHorizontally="true"

how to set layout's width to be 80% of the screen's full width?

like the question indicated, how can a simpleton like me could implement something like that via xml? if not, programmatically thanks.
update:
thanks for your help, now here is the result of my layout
<TableLayout android:layout_width="match_parent" android:layout_gravity="center"
android:layout_weight="10" android:layout_height="wrap_content">
<TableRow android:layout_weight="10">
<TextView android:id="#+id/labelVaccinesImmuDialog"
android:layout_weight="0"
android:layout_width="match_parent"
android:text="#string/vaccine_spinner_label" android:layout_gravity="center_vertical" />
<Spinner android:id="#+id/spinnerVaccinesImmuDialog"
android:layout_weight="8"
android:layout_width="0dp"
android:prompt="#string/vaccine_spinner_label" android:layout_height="44dp"/>
</TableRow>
<TableRow android:layout_weight="10">
<Button android:id="#+id/buttonDatePickerImmuDialog"
android:text="#string/datepicker_button_label"
android:layout_weight="0"
android:layout_width="match_parent"
android:layout_height="44dp"/>
<EditText android:id="#+id/editDateImmuDialog"
android:singleLine="true"
android:layout_weight="8"
android:padding="5px"
android:layout_width="0dp"
android:text="#string/immu_dialog_date_edit" android:layout_height="44dp"/>
</TableRow>
<TableRow android:layout_weight="10">
<TextView android:id="#+id/labelAdverseReactions"
android:text="#string/immu_dialog_adverse_reaction_label"
android:layout_gravity="center_vertical"
android:layout_weight="0"
android:layout_width="match_parent"/>
<Spinner android:id="#+id/spinnerAdverseReactionsImmuDialog"
android:layout_weight="8"
android:padding="5px"
android:layout_width="0dp"
android:text="#string/immu_dialog_adverse_reaction_spinner_label" android:layout_height="44dp"/>
</TableRow>
<TableRow android:layout_weight="10">
<TextView android:id="#+id/labelDoctorWhoAdministered"
android:text="#string/immu_dialog_doctor_administered_label"
android:layout_weight="0"
android:layout_gravity="center_vertical" android:layout_width="match_parent"/>
<EditText android:id="#+id/editDoctorWhoAdministeredImmuDialog"
android:singleLine="true"
android:layout_width="0dp"
android:layout_weight="8"
android:padding="5px"
android:text="#string/immu_dialog_doctor_administered_edit" android:layout_height="44dp"/>
</TableRow>
<TableRow android:layout_weight="10">
<Button android:id="#+id/buttonSubmitImmuDialog"
android:layout_weight="0"
android:text="#string/immu_dialog_submit_button" android:layout_height="44dp"/>
<Button android:id="#+id/buttonCancelImmuDialog"
android:layout_weight="8"
android:layout_width="0dp"
android:text="#string/immu_dialog_cancel_button" android:layout_height="44dp"/>
</TableRow>
</TableLayout>
in a linear layout, you could have another object to use up the other 20% then use layout_weight
<?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">
<LinearLayout android:orientation="horizontal"
android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_weight=".2" android:background="#ffaa0000" />
<LinearLayout android:id="#+id/textLayout"
android:orientation="horizontal" android:layout_height="fill_parent"
android:layout_width="fill_parent" android:layout_weight=".8" />
</LinearLayout>
in tablerows
<?xml version="1.0" encoding="utf-8"?>
<TableLayout android:id="#+id/TableLayout01"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TableRow android:id="#+id/TableRow01" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="#+id/TextView01" android:id="#+id/TextView01"
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_weight="10"></TextView>
<TextView android:text="#+id/TextView01" android:id="#+id/TextView01"
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_weight="1"></TextView>
</TableRow>
<TableRow android:id="#+id/TableRow01" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="#+id/TextView01" android:id="#+id/TextView01"
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_weight="10"></TextView>
<TextView android:text="#+id/TextView01" android:id="#+id/TextView01"
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_weight="1"></TextView>
</TableRow>
</TableLayout>

Android, layout_width and width, alignBaseline, TableLayout and layout_span related questions

[First, sorry, I couldn't come up with a more intelligent question title.]
Okay, hang with me while you read this long post.
I am new to Android, this is my very first dummy Pizza Order application. I am playing with XML layouts and have got some questions.
The editText_CardNo goes out of screen, its column isn't stretching, why? (Image)
[EDIT]
Can I specify a global layout_marginRight for all TableRow?
Resolved
I have aligned elements using alignBaseline but I don't see it working.
In the Crust section i have done layout_span="2" but no use, the second radio button's text still wraps. (Image)
Inner Tables e.g. TableLayout inside TableRow appear really ugly, only left half is visible, also tried with adding layout_span inside TableLayout or the TableRow containing it but no use. (Image)
How can I collapse the subsections e.g. TableLayout inside TableRow using properties?
main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="#+id/scrollView_PizzaOrder"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout android:id="#+id/tableLayout_PizzaOrder"
android:shrinkColumns="0"
android:stretchColumns="1"
android:layout_gravity="left"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow android:id="#+id/tableRow_PizzaType"
android:layout_marginTop="10px"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="Type"
android:id="#+id/textView_Type"
android:textStyle="bold"
android:layout_alignBaseline="#+id/spinner_Type"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<Spinner android:id="#+id/spinner_Type"
android:drawSelectorOnTop="true"
android:layout_width="200px"
android:layout_height="wrap_content">
</Spinner>
</TableRow>
<TableRow android:id="#+id/tableRow_PizzaSize"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="Size"
android:id="#+id/textView_Size"
android:textStyle="bold"
android:layout_alignBaseline="#+id/spinner_Size"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<Spinner android:id="#+id/spinner_Size"
android:drawSelectorOnTop="true"
android:layout_marginBottom="20px"
android:layout_width="200px"
android:layout_height="wrap_content">
</Spinner>
</TableRow>
<TableRow android:id="#+id/tableRow_Crust"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RadioGroup android:id="#+id/radioGroup_Crust"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton android:text="Single Crust"
android:id="#+id/radioButton_SingleCrust"
android:checked="true"
android:layout_span="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RadioButton>
<RadioButton android:text="Double Crust"
android:id="#+id/radiobutton_DoubleCrust"
android:layout_span="2"
android:layout_marginBottom="20px"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</RadioButton>
</RadioGroup>
</TableRow>
<TableRow android:id="#+id/tableRow_Toppings"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox android:text="Extra Toppings?"
android:id="#+id/checkbox_ExtraToppings"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
</TableRow>
<TableRow android:id="#+id/tableRow_ToppingsTable"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout android:id="#+id/tableLayout_Toppings"
android:layout_marginLeft="20px"
android:layout_gravity="left"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow android:id="#+id/tableRow_SelectToppings"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox android:text="Olives"
android:id="#+id/checkbox_Olives"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<CheckBox android:text="Cheese"
android:id="#+id/checkbox_Cheese"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
</TableRow>
<TableRow android:id="#+id/tableRow_SelectCustomToppings"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox android:text="Custom"
android:id="#+id/checkbox_Custom"
android:layout_marginRight="10px"
android:layout_alignBaseline="#+id/editText_Custom"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<EditText android:text=""
android:id="#+id/editText_Custom"
android:singleLine="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
</TableRow>
</TableLayout>
</TableRow>
<TableRow android:id="#+id/tableRow_SeparaterDrinks"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<View android:layout_height="2px"
android:background="#884400"
android:layout_span="2"
android:layout_margin="25px" />
</TableRow>
<TableRow android:id="#+id/tableRow_Drinks"
android:layout_span="2"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox android:text="Drinks?"
android:id="#+id/checkbox_Drinks"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
</TableRow>
<TableRow android:id="#+id/tableRow_DrinksTable"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout android:id="#+id/tableLayout_Drinks"
android:layout_marginLeft="20px"
android:layout_gravity="left"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow android:id="#+id/tableRow_SelectDrinksPepsi"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- Drinks links, for now static generation, later use XML and Dynamic Generation -->
<CheckBox android:text="Pepsi"
android:id="#+id/checkbox_Pepsi"
android:checked="true"
android:layout_alignBaseline="#+id/textView_QuantityPepsi"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<TextView android:text="Quantity:"
android:id="#+id/textView_QuanityPepsi"
android:textStyle="bold"
android:layout_alignBaseline="#+id/editText_QuantityPepsi"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:text="1"
android:id="#+id/editText_QuantityPepsi"
android:singleLine="true"
android:maxLength="3"
android:numeric="integer"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow android:id="#+id/tableRow_SelectDrinksCoke"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox android:text="Coke"
android:id="#+id/checkbox_Coke"
android:layout_alignBaseline="#+id/textView_QuantityCoke"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<TextView android:text="Quantity:"
android:id="#+id/textView_QuantityCoke"
android:textStyle="bold"
android:layout_alignBaseline="#+id/editText_QuantityCoke"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:text="0"
android:id="#+id/editText_QuantityCoke"
android:singleLine="true"
android:maxLength="3"
android:numeric="integer"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow android:id="#+id/tableRow_SelectDrinksSprite"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox android:text="Sprite"
android:id="#+id/checkbox_Sprite"
android:layout_alignBaseline="#+id/textView_QuantitySprite"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<TextView android:text="Quantity:"
android:id="#+id/textView_QuantitySprite"
android:layout_alignBaseline="#+id/editText_QuanitySprite"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:text="0"
android:id="#+id/editText_QuantitySprite"
android:singleLine="true"
android:maxLength="3"
android:numeric="integer"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow android:id="#+id/tableRow_SelectDrinksMountainDew"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox android:text="Mirinda"
android:id="#+id/checkbox_Mirinda"
android:layout_alignBaseline="#+id/textView_QuantityMirinda"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<TextView android:text="Quantity:"
android:id="#+id/textView_QuantityMirinda"
android:layout_alignBaseline="#+id/editText_QuantityMirinda"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:text="0"
android:id="#+id/editText_QuantityMirinda"
android:singleLine="true"
android:maxLength="3"
android:numeric="integer"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow android:id="#+id/tableRow_SelectDrinks7up"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox android:text="7up"
android:id="#+id/checkbox_7up"
android:layout_alignBaseline="#+id/textView_Quantity7up"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<TextView android:text="Quantity: "
android:id="#+id/textView_Quantity7up"
android:layout_alignBaseline="#+id/editText_Quantity7up"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:text="0"
android:id="#+id/editText_Quantity7up"
android:singleLine="true"
android:maxLength="3"
android:numeric="integer"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</EditText>
</TableRow>
</TableLayout>
</TableRow>
<TableRow android:id="#+id/tableRow_SeparaterMember"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<View android:layout_height="2px"
android:background="#884400"
android:layout_span="2"
android:layout_margin="25px" />
</TableRow>
<TableRow android:id="#+id/tableRow_Member"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<CheckBox android:text="Are you a Member?"
android:id="#+id/checkbox_Member"
android:layout_span="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
</TableRow>
<TableRow android:id="#+id/tableRow_MemberData"
android:layout_marginLeft="20px"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="Card #:"
android:id="#+id/textView_CardNo"
android:textStyle="bold"
android:layout_alignBaseline="#+id/editText_CardNo"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:text=""
android:id="#+id/editText_CardNo"
android:singleLine="true"
android:maxLength="8"
android:numeric="integer"
android:layout_width="200px"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow android:id="#+id/tableRow_SeparaterMemberData"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<View android:layout_height="2px"
android:background="#884400"
android:layout_span="2"
android:layout_margin="25px" />
</TableRow>
<TableRow android:id="#+id/tableRow_Name"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="Name:"
android:id="#+id/textView_Name"
android:layout_alignBaseline="#+id/editText_Name"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:text=""
android:id="#+id/editText_Name"
android:singleLine="true"
android:maxLength="35"
android:layout_width="200px"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow android:id="#+id/tableRow_CellNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="Cell:"
android:id="#+id/textView_Cell"
android:textStyle="bold"
android:layout_alignBaseline="#+id/editText_Cell"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:text=""
android:id="#+id/editText_Cell"
android:singleLine="true"
android:phoneNumber="true"
android:maxLength="15"
android:layout_width="200px"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow android:id="#+id/tableRow_Address"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:text="Address:"
android:id="#+id/textView_Address"
android:textStyle="bold"
android:layout_alignBaseline="#+id/editText_Address"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
<EditText android:text=""
android:id="#+id/editText_Address"
android:singleLine="true"
android:maxLength ="200"
android:layout_width="200px"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow android:id="#+id/tableRow_PlaceOrder"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:text="Place Order!"
android:id="#+id/button_PlaceOrder"
android:onClick="placeOrder"
android:layout_column="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</TableRow>
</TableLayout>
</ScrollView>
layout_alignBaseline is for RelativeLayout only. LinearLayout (and therefore TableLayout) perform baseline alignment by default.
The layout_span needs to go on the RadioGroup, not the RadioButtons.
The editText_CardNo goes out of screen because you set its width to android:layout_width="200px". This is too large. The column is stretched only when smaller than the screen. You want it to shrink. You can set a column both shrinkable AND stretchable.
How can i collapse the subsections e.g. TableLayout inside TableRow using properties? >> Use android:visibility="gone"

android table layout one for both (landscape and portrait view)

I want to create the following layout which should be 100% in landscape form as displaying in portrait form.
alt text http://www.freeimagehosting.net/uploads/b12bb68569.png
here is my code which i tried but not working
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:stretchColumns="0">
<TableRow>
<TableLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow>
<TableLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal">
<TableRow>
<TextView android:id="#+id/reviewItemEntityName"
android:layout_height="wrap_content" android:text="12345"
android:textColor="#color/maroon" />
<ImageView android:id="#+id/reviewItemStarRating"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="#drawable/title_1_star" />
</TableRow>
</TableLayout>
</TableRow>
<TableRow>
<TextView android:id="#+id/reviewItemDescription"
android:layout_width="0dip" android:layout_height="wrap_content"
android:text="Description comes here" android:textSize="12sp" />
</TableRow>
</TableLayout>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="#drawable/arrow_nxt"
android:layout_gravity="center_vertical"
android:layout_alignParentRight="true" />
</TableRow>
</TableLayout>
i think this is what your looking for, remember to play with the "android:layout_weight" value, it will basically tell the widgets how much they should expand (use the available free space).
have fun.
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableRow android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TableLayout android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<TableRow>
<TextView android:text="TextView Up Left"
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:layout_weight="1">
</TextView>
<ImageView android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/btn_plus"
android:gravity="right">
</ImageView>
</TableRow>
<TableRow>
<TextView android:text="Text view with padding"
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="20.0dp"
android:paddingLeft="20.0dp"
android:paddingRight="20.0dp"
android:paddingTop="20.0dp"
android:layout_weight="1">
</TextView>
</TableRow>
</TableLayout>
<TableLayout android:id="#+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0">
<TableRow android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
<ImageView android:id="#+id/ImageView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/btn_minus"
android:layout_gravity="center"
>
</ImageView>
</TableRow>
</TableLayout>
</TableRow>
</TableLayout>

Categories

Resources