Long text in TextView - android

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"

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.

Including a new image view inside scroll view causing error

i am having a scroll view like this . There is an image view with id="#+id/but_logo_view1 inside that. I wanted to add another image view to right of that. I tried several ways. But am getting a force close error. How can I achieve the desired result. Please help
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/lineartop"
android:layout_marginBottom="50dip"
android:paddingLeft="10dip"
android:paddingRight="10dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center|center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="#+id/but_logo_view1"
android:layout_width="60dip"
android:visibility="visible"
android:layout_height="60dip"
android:scaleType="fitXY"
android:src="#drawable/camera" />
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="10dip"
android:gravity="center" >
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="User Name"
android:textColor="#000000"
android:textSize="18dip" />
<EditText
android:id="#+id/edit_signup_user"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:maxLength="10"
android:textSize="18dip"
android:padding="3dip"
android:hint="Name"
android:singleLine="true"
android:textColor="#color/black" android:gravity="center"/>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="10dip"
android:gravity="center" >
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Email"
android:textColor="#000000"
android:textSize="18dip" />
<EditText
android:id="#+id/edit_signup_email"
android:layout_width="150dip"
android:layout_height="fill_parent"
android:hint="optional"
android:padding="3dip"
android:singleLine="true"
android:textSize="18dip"
android:textColor="#color/black"
android:textColorHint="#858585" android:gravity="center"/>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dip"
android:gravity="center" >
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Password"
android:textColor="#000000"
android:textSize="18dip" />
<EditText
android:id="#+id/edit_signup_passwd"
android:textSize="18dip"
android:singleLine="true"
android:inputType="number" android:maxLength="4"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:textColor="#color/black"
android:padding="3dip"
/>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="20dip"
android:gravity="center" >
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Retype Password"
android:textColor="#000000"
android:textSize="18dip" />
<EditText
android:id="#+id/edit_signup_repasswd"
android:textSize="18dip"
android:singleLine="true"
android:inputType="number" android:maxLength="4"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:textColor="#color/black"
android:padding="3dip"
/>
</TableRow>
</TableLayout>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="#+id/but_signup_twitter"
android:layout_width="70dip"
android:layout_height="70dip"
android:background="#drawable/twitter_icon"
android:visibility="invisible" />
<Button
android:id="#+id/but_signup_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/sign_in_unlit" android:typeface="serif" android:layout_marginLeft="20dip" android:layout_marginRight="20dip"/>
<Button
android:id="#+id/but_signup_fb"
android:layout_width="70dip"
android:layout_height="70dip"
android:background="#drawable/facebook_icon" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:gravity="center|right" >
</TableRow>
</LinearLayout>
</ScrollView>
The error may be occurring because it is a LinearLayout, You could try using instead and setting the imageview like this :
<ImageView
android:id="#+id/image2"
android:layout_alignLeft="#+id/but_logo_view1"
android:layout_width="60dip"
android:visibility="visible"
android:layout_height="60dip"
android:scaleType="fitXY"/>
You can then adjust the padding or the x-axis according to how far away you want the image to be.
I hope this helps.
Not sure if the previous poster missed a word in his response, but to use 'layout_alignLeft' you need to use RelativeLayout instead of LinearLayout

How to use ScrollView in Android?

I have an XML layout file, but the text is more than fits into the screen size. What do I need to do in order to make a ScrollView?
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1" >
<TableRow>
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="10dip"
android:layout_marginRight="5dip"
android:tint="#55ff0000"
android:src="#drawable/icon" />
</TableRow>
<TableRow>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Name " />
<TextView android:id="#+id/name1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Veer" />
</TableRow>
<TableRow>
<TextView android:id="#+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Age" />
<TextView android:id="#+id/age1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="23" />
</TableRow>
<TableRow>
<TextView android:id="#+id/gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Gender" />
<TextView android:id="#+id/gender1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Male" />
</TableRow>
<TableRow>
<TextView android:id="#+id/profession"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Professsion" />
<TextView android:id="#+id/profession1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Mobile Developer" />
</TableRow>
<TableRow>
<TextView android:id="#+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Phone" />
<TextView android:id="#+id/phone1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="03333736767" />
</TableRow>
<TableRow>
<TextView android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Email" />
<TextView android:id="#+id/email1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="veer.developer#gmail.com" />
</TableRow>
<TableRow>
<TextView android:id="#+id/hobby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Hobby" />
<TextView android:id="#+id/hobby1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Play Games" />
</TableRow>
<TableRow>
<TextView android:id="#+id/ilike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" I like" />
<TextView android:id="#+id/ilike1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Java, Objective-c" />
</TableRow>
<TableRow>
<TextView android:id="#+id/idislike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" I dislike" />
<TextView android:id="#+id/idislike1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Microsoft" />
</TableRow>
<TableRow>
<TextView android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Address" />
<TextView android:id="#+id/address1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Johar Mor" />
</TableRow>
</TableLayout>
Just make the top-level layout a ScrollView:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1">
<!-- everything you already have -->
</TableLayout>
</ScrollView>
How to use ScrollView
Using ScrollView is not very difficult. You can just add one to your layout and put whatever you want to scroll inside. ScrollView only takes one child so if you want to put a few things inside then you should make the first thing be something like a LinearLayout.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- things to scroll -->
</LinearLayout>
</ScrollView>
If you want to scroll things horizontally, then use a HorizontalScrollView.
Making the content fill the screen
As is talked about in this post, sometimes you want the ScrollView content to fill the screen. For example, if you had some buttons at the end of a readme. You want the buttons to always be at the end of the text and at bottom of the screen, even if the text doesn't scroll.
If the content scrolls, everything is fine. However, if the content is smaller than the size of the screen, the buttons are not at the bottom.
This can be solved with a combination of using fillViewPort on the ScrollView and using a layout weight on the content. Using fillViewPort makes the ScrollView fill the parent area. Setting the layout_weight on one of the views in the LinearLayout makes that view expand to fill any extra space.
Here is the XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"> <--- fillViewport
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/textview"
android:layout_height="0dp" <---
android:layout_weight="1" <--- set layout_weight
android:layout_width="match_parent"
android:padding="6dp"
android:text="hello"/>
<LinearLayout
android:layout_height="wrap_content" <--- wrap_content
android:layout_width="match_parent"
android:background="#android:drawable/bottom_bar"
android:gravity="center_vertical">
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Accept" />
<Button
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Refuse" />
</LinearLayout>
</LinearLayout>
</ScrollView>
The idea for this answer came from a previous answer that is now deleted (link for 10K users). The content of this answer is an update and adaptation of this post.
There are two options. You can make your entire layout to be scrollable or only the TextView to be scrollable.
For the first case,
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1" >
<TableRow>
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="10dip"
android:src="#drawable/icon"
android:tint="#55ff0000" >
</ImageView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Name " >
</TextView>
<TextView
android:id="#+id/name1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Veer" >
</TextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/age"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Age" >
</TextView>
<TextView
android:id="#+id/age1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="23" >
</TextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Gender" >
</TextView>
<TextView
android:id="#+id/gender1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Male" >
</TextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/profession"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Professsion" >
</TextView>
<TextView
android:id="#+id/profession1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Mobile Developer" >
</TextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Phone" >
</TextView>
<TextView
android:id="#+id/phone1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="03333736767" >
</TextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Email" >
</TextView>
<TextView
android:id="#+id/email1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="veer.developer#gmail.com" >
</TextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/hobby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Hobby" >
</TextView>
<TextView
android:id="#+id/hobby1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Play Games" >
</TextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/ilike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" I like" >
</TextView>
<TextView
android:id="#+id/ilike1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Java, Objective-c" >
</TextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/idislike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" I dislike" >
</TextView>
<TextView
android:id="#+id/idislike1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Microsoft" >
</TextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:text=" Address" >
</TextView>
<TextView
android:id="#+id/address1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Johar Mor" >
</TextView>
</TableRow>
<Relativelayout>
</Relativelayout>
</TableLayout>
</RelativeLayout>
</ScrollView>
or, as I said you can use scrollView for TextView alone.
A ScrollView is a special type of FrameLayout in that it allows users to scroll through a list of views that occupy more space than the physical display.I just add some attributes .
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars = "vertical"
android:scrollbarStyle="insideInset"
>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
>
<!-- Add here which you want -->
</TableLayout>
</ScrollView>
As said above you can put it inside a ScrollView... and if you want the Scroll View to be horizontal put it inside HorizontalScrollView... and if you want your component (or layout) to support both put inside both of them like this:
<HorizontalScrollView>
<ScrollView>
<!-- SOME THING -->
</ScrollView>
</HorizontalScrollView>
and with setting the layout_width and layout_height ofcourse.
Put your TableLayout inside a ScrollView Layout.That will solve your problem.
To scroll data in text view you can use this to your text view.
and add
and for anything other layout you can just add scroll view on layout as people are saying above.
/**
android:scrollable=true at textview in xml layout.
TextView txtScroll = (TextView) findViewById(R.id.txt1);
txtScroll.setMovementMethod(new ScrollingMovementMethod());
*//
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<RadioButton
android:id="#+id/butonSecim1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight=".50"
android:text="#string/buton1Text" />
<RadioButton
android:id="#+id/butonSecim2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight=".50"
android:text="#string/buton2Text" />
</RadioGroup>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableLayout
android:id="#+id/bilgiAlani"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="invisible" >
<TableRow
android:id="#+id/BilgiAlanitableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/bilgiMesaji"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight=".100"
android:ems="10"
android:gravity="left|top"
android:inputType="textMultiLine" />
</TableRow>
</TableLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/metin4"
android:layout_height="match_parent"
android:layout_weight=".100"
android:text="deneme" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/metin5"
android:layout_height="match_parent"
android:layout_weight=".100"
android:text="deneme" />
</TableRow>
</TableLayout>
</ScrollView>

spinner expanding beyond screen bounds

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.

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"

Categories

Resources