How to add scroll view in tablelayout? so is show all textview - android

I finally solve me last post issue by weight attribute but one problem is come when I give multi line text last Textview not show which in this url http://imgur.com/ApL5c
How do I add scroll view in my code?
<?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="wrap_content"
android:stretchColumns="1"
android:weightSum="11"
android:layout_margin="5dp">
<TableRow>
<TextView
style="#style/StyleLabel"
android:text="#string/name_lbl"/>
<TextView
android:id="#+id/nameText"
android:layout_weight="2"
style="#style/StyleText"/>
</TableRow>
<TableRow>
<TextView
style="#style/StyleLabel"
android:text="#string/cap_lbl"/>
<TextView
android:id="#+id/capText"
android:layout_weight="2"
style="#style/StyleText"/>
</TableRow>
<TableRow>
<TextView
style="#style/StyleLabel"
android:text="#string/code_lbl"/>
<TextView
android:id="#+id/codeText"
android:layout_weight="1"
style="#style/StyleText"/>
</TableRow>
<TableRow>
<TextView
style="#style/StyleLabel"
android:text="#string/DoneDate_lbl"/>
<TextView
android:id="#+id/Location_lbl"
android:layout_weight="1"
style="#style/StyleText"/>
</TableRow>
<TableRow>
<TextView
style="#style/StyleLabel"
android:text="#string/Notes_lbl"/>
<TextView
android:id="#+id/Notes_lbl"
android:layout_weight="4"
style="#style/StyleText"
/>
</TableRow>
<TableRow>
<TextView
style="#style/StyleLabel"
android:text="#string/person_lbl"/>
<TextView
android:id="#+id/Person_lbl"
android:layout_weight="1"
style="#style/StyleText"/>
</TableRow>

Simply surround it in a scrollview like the following--
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="1"
android:weightSum="11"
android:layout_margin="5dp">
<TableRow>
<TextView
android:text="textview1"/>
<TextView
android:id="#+id/nameText"
android:text="tewgoijirtgujerioug"
android:lines="15" //You can add lines to make your textview occupy the no of lines you want instead of weight.
android:layout_weight="2"
/>
</TableRow>
............
.............
</TableLayout>
</ScrollView>
Hope this helps.

Related

Change the a particular textview in multiple textviews when it's respective button is clicked

I have multiple items and each item has a textview specifying the number of items selected by the user. When the user clicks on a button, the respective textview must be changed displaying updated number. Is there any other way than giving each item's button and textview separate ids and writing code for them ?
Here is the xml file that helps to understand I'm new to android programming and any advice or help would be a lot of help to me. Thanks.
<TableLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<TableRow>
<LinearLayout android:layout_height="200dp" android:orientation="vertical"
android:layout_width="wrap_content"
android:background="#drawable/abc"/>
</TableRow>
<TableRow>
<TextView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:padding="5dp"
android:text="ABC"/>
</TableRow>
<TableRow>
<LinearLayout android:orientation="horizontal">
<TextView
android:id="#+id/itemsNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Items : 0"/>
<Button
android:id="#+id/plusBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD"/>
</LinearLayout>
</TableRow>
<TableRow>
<LinearLayout android:layout_height="300dp" android:orientation="vertical"
android:layout_width="wrap_content"
android:background="#drawable/xyz"/>
</TableRow>
<TableRow>
<TextView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="XYZ"/>
</TableRow>
<TableRow>
<LinearLayout android:orientation="horizontal">
<TextView
android:id="#id/itemsNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Items : 0"/>
<Button
android:id="#id/plusBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD"/>
</LinearLayout>
</TableRow>
<TableRow>
<LinearLayout android:layout_height="300dp" android:orientation="vertical"
android:layout_width="wrap_content"
android:background="#drawable/ijk"/>
</TableRow>
<TableRow>
<TextView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="IJK"/>
</TableRow>
<TableRow>
<LinearLayout android:orientation="horizontal">
<TextView
android:id="#id/itemsNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Items : 0"/>
<Button
android:id="#id/plusBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD"/>
</LinearLayout>
</TableRow>
<TableRow>
<LinearLayout android:layout_height="300dp" android:orientation="vertical"
android:layout_width="wrap_content"
android:background="#drawable/abc1"/>
</TableRow>
<TableRow>
<TextView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="ABC1"/>
</TableRow>
<TableRow>
<LinearLayout android:orientation="horizontal">
<TextView
android:id="#id/itemsNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Items : 0"/>
<Button
android:id="#id/plusBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD"/>
</LinearLayout>
</TableRow>
</TableLayout>
If they are going to always be the same layout, you should create a custom widget that extends View that contains the TextView and Button. If you never need to reference them from code you wouldn't need to write anything after doing it once. If you do need to reference it from code, you are going to have to set an id on your custom view widget in order to reference it.

TextView alignment in the TableRow

There are two TableRows in the TableLayout, and each TableRow contains two TextViews:
<?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="wrap_content"
android:orientation="horizontal" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" >
<TextView
android:id="#+id/textTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textTitle"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="63dp"
android:layout_marginRight="10dp" >
<TextView
android:id="#+id/textHall"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/textPrice"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp" />
</TableRow>
</TableLayout>
If textHall contains a short Word, textTitle (Some Text) located at the correct position:
But if textHall contains a long Second Word, before textTitle (Some Text) appears a large indentation:
What is the reason?
Thanks.
You should give weight for your layouts and rows. I adapted your code. Here is the one that should be.
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:weightSum="2" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:orientation="horizontal" >
<TextView
android:id="#+id/textTime"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="10:30" />
<TextView
android:id="#+id/textTitle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:layout_marginLeft="10dp"
android:text="Some Text" />
</LinearLayout>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="63dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:weightSum="2" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:orientation="horizontal" >
<TextView
android:id="#+id/textHall"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Some Word" />
<TextView
android:id="#+id/textPrice"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:text="200" />
</LinearLayout>
</TableRow>
You can put any margin value for your second row as you wish.
Hope this may help.
Your textHall and textTime both fall into same column and the width of that column is set to the width of textHall(as this is having more width) as a result your textTime textview's width is increasing when you increase text in textHall.

How to right align text

I was trying to change the alignment of text. This is what i have:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content">
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content">
<TableRow>
<TextView
android:id="#+id/ctime"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:text="time" />
</TableRow>
<TableRow>
<TextView
android:id="#+id/cstatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_weight="100"
android:text="status" />
</TableRow>
</TableLayout>
</LinearLayout>
Everything is left-aligned in the output even after setting android:layout_gravity="right".
This is a part of the layout, as I cant post the entire layout.
use this one
android:gravity="right"

Android Layout Percentage/Proportion Resize

I have 3 layouts. First and third ones are RelativeLayout and the middle one is TableLayout. What I want is the TableLayout should lay over 80% of screen. And 10% for the others. How could I do this? android:layout_weight did not help me. Please could you put a code for this solution?
Ok here are some steps:
set to the relative and table layouts android:layout_width to 0dp
in the parent layout add android:weightSum to 10
in each of the 3 child layouts add android:layout_weight and set the first & third to the value of 1 and the middle table layout to 8.
Here is the code and screenshot:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:weightSum="10" >
<RelativeLayout
android:id="#+id/leftPane"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:background="#336699"
android:layout_weight="1">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10% wide"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#00FFFF">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="row 1" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#33FFFF" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="row 2" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#66FFFF" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="row 3" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#99FFFF" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="row 4" />
</TableRow>
</TableLayout>
<RelativeLayout
android:id="#+id/rightPane"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:background="#336699"
android:layout_weight="1">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10% wide"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
</LinearLayout>

In TableLayout TableRow align button right?

I am trying to align a button to the right of a TableRow. Inside the TableRow I have two textviews and a button. The middle textview is hidden when the button is displayed. This is done inside my adapter by setting the textview visibility to gone.
I am not sure what the best approach is to aligning the button to the right when it is displayed.
Here is my Layout file:
<?xml version="1.0" encoding="UTF-8" ?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget28"
android:stretchColumns="1"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingLeft="10sp"
android:descendantFocusability="blocksDescendants"
>
<TableRow>
<TextView
android:id="#+id/textTopLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium">
</TextView>
<TextView
android:id="#+id/textTopRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium">
</TextView>
</TableRow>
<TableRow>
<TextView
android:id="#+id/textBottomLeft"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
<TextView
android:id="#+id/textBottomRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
<Button
android:id="#+id/btnSessionResume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Resume"
android:visibility="invisible"
android:layout_marginRight="20px"
android:layout_alignParentRight="true">
</Button>
</TableRow>
</TableLayout>
The button is in the bottom TableRow.
Here is a screenshot of what the layout currently looks like:
//use android:layout_span and remove your right margin for you button
<?xml version="1.0" encoding="UTF-8" ?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget28"
android:stretchColumns="1"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:paddingLeft="10sp"
android:descendantFocusability="blocksDescendants"
>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_span="2">
<TextView
android:id="#+id/textTopLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium">
</TextView>
<TextView
android:id="#+id/textTopRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium">
</TextView>
</TableRow>
<TableRow android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textBottomLeft"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
<TextView
android:id="#+id/textBottomRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall">
</TextView>
<Button
android:id="#+id/btnSessionResume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Resume"
android:visibility="invisible"
android:layout_marginRight="5dp"
android:layout_alignParentRight="true">
</Button>
</TableRow>
</TableLayout>
Perhaps you can have a relative layout in the table row and then use android:layout_alignParentLeft on the TextViews and android:layout_alignParentRight on the button.

Categories

Resources