Table too wide even with match parent in android studio - android

I was trying to make an app for an assignment in which I was using a table however the screen on the preview was larger than the screen of my phone so the table ended up to be too big I was told to use match parent to make the table auto adjust to the screen size on the phone however that did not work so i am seeking help.Screenshot of issue
Edit: I took the edit text and checkbox out of the table and that fixed the issue.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="TOY CARS" />
<TableLayout
android:id="#+id/table1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textview1"
android:stretchColumns="0,1,2,3,4">
<TableRow>
<TextView
android:id="#+id/textview2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_column="0"
android:text="Hot Wheels" />
<TextView
android:layout_column="1"
android:text="$50"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="2"
android:text="ADD" />
<Button
android:id="#+id/button2"
android:text="REMOVE"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="3"/>
<TextView
android:id="#+id/textview6"
android:text="0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_column="4"/>
</TableRow>
<TableRow>
<TextView
android:id="#+id/textview3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:text="Trandformers" />
<TextView
android:layout_column="1"
android:text="$100" />
<Button
android:id="#+id/button3"
android:text="ADD"/>
<Button
android:id="#+id/button4"
android:text="REMOVE"/>
<TextView
android:id="#+id/textview7"
android:text="0"/>
</TableRow>
<TableRow>
<TextView
android:id="#+id/textview4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:text="Tonka" />
<TextView
android:layout_column="1"
android:text="$150" />
<Button
android:id="#+id/button5"
android:text="ADD"/>
<Button
android:id="#+id/button6"
android:text="REMOVE"/>
<TextView
android:id="#+id/textview8"
android:text="0"/>
</TableRow>
<TableRow>
<TextView
android:id="#+id/textview5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:text="ZipZaps" />
<TextView
android:layout_column="1"
android:text="$200" />
<Button
android:id="#+id/button7"
android:text="ADD"/>
<Button
android:id="#+id/button8"
android:text="REMOVE"/>
<TextView
android:id="#+id/textview9"
android:text="0"/>
</TableRow>
<TableRow>
<TextView
android:id="#+id/textview10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coupon Code: "
android:layout_column="0"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Coupon Code"
android:layout_toRightOf="#+id/textview10"/>
</TableRow>
<TableRow>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:text="VAT"/>
</TableRow>
</TableLayout>
<TextView
android:id="#+id/textview11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Area Code"
android:layout_below="#+id/table1"/>
<RadioGroup
android:id="#+id/radiogroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textview11">
<RadioButton
android:id="#+id/radiobutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="33100-34000"/>
<RadioButton
android:id="#+id/radiobutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="34000-35001"/>
<RadioButton
android:id="#+id/radiobutton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00000"/>
</RadioGroup>
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/radiogroup1"
android:text="Calculate"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="$00000"
android:layout_below="#+id/radiogroup1"
android:layout_toRightOf="#+id/button9"
android:layout_marginLeft="20px"
android:textSize="25dp"/>
</RelativeLayout>

I would try adding the android:shrinkColumns attribute in the same way you added the android:stretchColumns attirbute. The stretchColumns attribute allows the table columns to stretch to fit a large parent, and the shrinkColumns attribute will allow them to shrink to fit a small parent. You can have both attributes on the layout at the same time, and they'll both work.

Related

Android Eclipse - Increasing side margins on my table layout

I'm a bit confused on how to increase the overall width of my TableLayout in order to become closer to the sides of the screen.
I'm not sure if I adjust this in the actual TableLayout itself, or in the parent RelativeLayout...??
Image:
Any thoughts?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.funkycalc.MainActivtiy\" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:text="CLR" />
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:text="DEL" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button5"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:id="#+id/button6"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:id="#+id/button7"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button9"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />
<Button
android:id="#+id/button10"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5" />
<Button
android:id="#+id/button11"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6" />
<Button
android:id="#+id/button12"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button13"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7" />
<Button
android:id="#+id/button14"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8" />
<Button
android:id="#+id/button15"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9" />
<Button
android:id="#+id/button16"
style="?android:attr/buttonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:text="0" />
<Button
android:id="#+id/button18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="." />
<Button
android:id="#+id/button20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="x" />
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="4"
android:text="=" />
</TableRow>
<TableRow
android:id="#+id/tableRow7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
</TableLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:text="Result"
android:textSize="55dp" />
You can use match_parent in the table layout so it takes the full width of the parent then adjust left and right padding to generate the desired separation. Bear in mind that you already have a padding defined in your relative layout hence you you will need to play with both values.
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
You set android:layout_width="wrap_content" to the TableLayout which causes it to be just wide enough to show all the content. Try using match_parent to make it take the entire parent width:
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
Another thing that shrinks your TableLayout down is this:
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
in the parent RelativeLayout. If the first step does not suit your needs, you can try setting lower paddingLeft and paddingRight values.
try this edit
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.funkycalc.MainActivtiy\" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
the padding values was the problem...

How do I align these buttons in Android?

I want these buttons to be aligned on top of each other. As you can see, since the text in the second row is shorter, the buttons take up a little more space to fill everything up. I'd rather have button 5 directly below and aligned with button 1.
Here's my xml for the layout:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp">
<TextView android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:text="Start Corner:"
/>
<Button
android:id="#+id/start_corner_btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
android:layout_weight="15"/>
<Button
android:id="#+id/start_corner_btn_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:layout_weight="15"/>
<Button
android:id="#+id/start_corner_btn_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3"
android:layout_weight="15"/>
<Button
android:id="#+id/start_corner_btn_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4"
android:layout_weight="15"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp">
<TextView android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:text="2nd Corner:"
/>
<Button
android:id="#+id/second_corner_btn_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5"
android:layout_weight="15"/>
<Button
android:id="#+id/second_corner_btn_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:layout_weight="15"/>
<Button
android:id="#+id/second_corner_btn_7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7"
android:layout_weight="15"/>
<Button
android:id="#+id/second_corner_btn_8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:layout_weight="15"/>
</LinearLayout>
As always, I'll bet I am close, but probably missing one thing!
Try TableLayout:
<TableLayout
android:id="#+id/tableBtns"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="15"
android:text="Start Corner:"/>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="15"
android:text="1" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="15"
android:text="2" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="15"
android:text="3" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="15"
android:text="4" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="15"
android:text="2nd Corner:" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="15"
android:text="5" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="15"
android:text="6" />
<Button
android:id="#+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="15"
android:text="7" />
<Button
android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="15"
android:text="8" />
</TableRow>
</TableLayout>
you can separate the space with two vertical linearlayouts,
in the left one put your textViews and in the right one put your Buttons
Instead of using "wrap_content" for width, use some fixed value for the textviews. Or, better yet, replace the entire thing with RelativeLayout and align Button 5 to be aligned to the left of Button 1 using android:layout_alignLeft directive.

Why layout is different in graphical layout and AVD , where both are working on android 2.2 API 8

I am making one layout but when i see that layout in graphical layout and in AVD manager, AVD manager displays somewhat different layout than graphical layout. Please help me to fix this problem.
look at below..
enter link description here
Unfortunatley I cannot comment on your post.. but could you please upload your .xml file? Maybe you built your layout on a "screen" with a resolution different from the one of AVD VM or you are using a relative layout. Just post the .xml
Try changing your xml layout like this :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="15dp"
android:paddingRight="15dp"
tools:context=".MainActivity"
android:orientation="vertical"
android:background="#54616d"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dial Number"
android:textColor="#f7edb3"
android:textSize="20dp"
android:layout_marginTop="20dp"
android:layout_marginLeft="0dp"
/>
<View
android:id="#+id/separator"
android:background="#f7edb3"
android:layout_width = "fill_parent"
android:layout_height="1dip"
android:layout_centerVertical ="true"
android:layout_alignParentTop="true"
android:layout_marginTop="15dp"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:background="#fff"
android:layout_marginTop="15dp"
/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFF"
android:text="1"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="3"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="2"
android:textSize="25dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFF"
android:text="4"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="6"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="5"
android:textSize="25dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFF"
android:text="7"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="8"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="9"
android:textSize="25dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#FFF"
android:text="*"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="0"
android:textSize="25dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dip"
android:layout_weight="1"
android:background="#FFF"
android:text="#"
android:textSize="25dp" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp" >
<Button
android:id="#+id/dial"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#c79c00"
android:text="Dial" />
</TableRow>
</TableLayout>
</LinearLayout>

android calculator

i was designing a calculator similar to win 7 calc i have used colspan to make 0 button to size of two cols but i am not getting how to make = button to size of two rows i am using table layout..
i tried it with android:layout_span but its working only for colspan is ther any thing for row span
<?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="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="257dp"
android:layout_height="wrap_content" >
<requestFocus />
</EditText>
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="7" android:textSize="40dp"/>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="9" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="4" />
</TableRow>
<Button
android:id="#+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5" />
<Button
android:id="#+id/button8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6" />
<Button
android:id="#+id/button9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/" />
<Button
android:id="#+id/button10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="%" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/button11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
</TableRow>
<Button
android:id="#+id/button12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:id="#+id/button13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
<Button
android:id="#+id/button14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
<Button
android:id="#+id/button15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="=" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:
>
<Button
android:id="#+id/button16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:text="0" />
<Button
android:id="#+id/button17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="." />
<Button
android:id="#+id/button18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />
</TableRow>
</TableLayout>
</LinearLayout>
You can't do it in table view..So i suggest u to use ur last column outside of the table layout. And change the parent layout to Relative Layout.

How to make table rows scrollable in android

Below given is my layout which is I am using for displaying a table, which have a number of rows. the problem is this table have more no of rows than the screen can contain, so i want rows to be scrollable so that if i scroll down i can reach to the rows which is not visible in current screen.
i used isScrollContainer="true" bur this does not solve my problem
Can you please suggest which property can i use to solve the problem
<TableLayout android:layout_height="wrap_content" android:isScrollContainer="true" >
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="center">
<View android:layout_gravity="center" android:layout_height="30px"
android:background="#android:color/darker_gray"
android:layout_width="400px" />
<TextView android:layout_width="wrap_content" style="#style/styleName"
android:id="#+id/tv_add_ticket" android:text="Update Ticket on Assembloid Space"
android:layout_height="wrap_content" android:layout_marginLeft="5px"
android:layout_marginRight="2px" android:layout_marginTop="2px"
android:layout_marginBottom="2px">
</TextView>
</RelativeLayout>
</TableLayout>
<TableLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20px" android:isScrollContainer="true"
xmlns:android="http://schemas.android.com/apk/res/android"
android:baselineAligned="true" android:background="#565051"
android:layout_marginTop="50px">
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/ticket_status"
android:text="Status " android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
<!-- <EditText android:layout_width="250px" android:layout_height="wrap_content"
android:id="#+id/et_ticket_status"></EditText> -->
<Spinner android:layout_width="100px" android:layout_height="wrap_content"
android:id="#+id/spn_up_ticket_status"></Spinner>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/ticket_priority"
android:text="Priority" android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
<Spinner android:layout_width="200px" android:layout_height="wrap_content"
android:id="#+id/spn_up_ticket_priority"></Spinner>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/ticket_summary"
android:text="Summary" android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
/>
<EditText android:layout_width="250px" android:id="#+id/et_ticket_summary"
android:layout_height="wrap_content" android:autoText="true">
</EditText>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/ticket_discription"
android:text="Discription" android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
/>
<EditText android:layout_width="250px" android:id="#+id/et_ticket_Discription"
android:layout_height="wrap_content" android:autoText="true"></EditText>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/estimated_hour"
android:text="Estimated Hours" android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
/>
<EditText android:layout_width="250px" android:id="#+id/et_estimated_hour"
android:layout_height="wrap_content" android:autoText="true"></EditText>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/worked_hour"
android:text="Worked Hours" android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
<EditText android:layout_width="250px" android:id="#+id/et_worked_hour"
android:layout_height="wrap_content" android:autoText="true"></EditText>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/ticket_comment"
android:text="Comment" android:layout_column="1" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text=":"
android:layout_column="2" android:layout_marginTop="5px"
android:layout_marginRight="5px" />
/>
<EditText android:layout_width="250px" android:id="#+id/et_ticket_comment"
android:layout_height="wrap_content" android:autoText="true">
</EditText>
</TableRow>
<TableRow>
<Button android:layout_width="wrap_content" android:text="Comments"
android:layout_height="wrap_content" android:id="#+id/comment_ticket_button" android:layout_column="1" ></Button>
<Button android:layout_width="wrap_content" android:text="#string/update_ticket"
android:layout_height="wrap_content" android:id="#+id/update_ticket_button" android:layout_column="3"></Button>
</TableRow>
<TextView android:id="#+id/error_ticket_text"
android:layout_centerHorizontal="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_below="#+id/login_button" />
You should wrap your TableLayout inside a ScrollView with appropriate height
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="100dp">
<TableLayout..>
</TableLayout>
</ScrollView>
You should use ScrollView as the root layout to solve your problem.

Categories

Resources