I created a TableLayout for my application. Everything is working fine, but once I add the button image at the bottom of the page the alignment breaks. Here is an image before entering the button image code:
After entering the code for the button images:
My xml layout:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*"
android:background="#drawable/authenticinfo">
<TableRow
android:id="#+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="18dp"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="38dp"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="38dp"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<ImageView
android:id="#+id/imview"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
/>
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="20dp"
android:gravity="center"
></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/ProductID1"
android:text="Product ID"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/ProductID2"
android:text=":"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/ProductID3"
android:text="92173ad0"
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow7"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/ProductID4"
android:text="产品编号 "
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/ProductID5"
android:text=":"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/ProductID6"
android:text="92173ad0"
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow8"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="8dp"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow9"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/Manf1"
android:text="生产日期 "
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/Manf2"
android:text=":"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/Manf3"
android:text="01 Jan 2012"
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow10"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/Exp1"
android:text="有效日期 "
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/Exp2"
android:text=":"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/Exp3"
android:text="01 Jan 2015"
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow11"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="8dp"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow12"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/Mas1"
android:text="马来西亚出口许可证 "
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/Mas2"
android:text=":"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/Mas3"
android:text=""
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow13"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/China1"
android:text="中国的进口许可证 "
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/China2"
android:text=":"
android:textStyle="bold"
android:typeface="serif"></TextView>
<TextView
android:id="#+id/China3"
android:text=""
android:textStyle="bold"
android:typeface="serif"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow14"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:typeface="serif"
android:textSize="28dp"
android:gravity="center"
android:layout_span="6"></TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow15"
>
<ImageView
android:id="#+id/imbutt"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:background="#+drawable/buttonmainmenuoff"
/>
<ImageView
android:id="#+id/imbutt"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:background="#+drawable/buttonmainmenuoff"
/>
<ImageView
android:id="#+id/imbutt"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:background="#+drawable/buttonmainmenuoff"
/>
</TableRow>
</TableLayout>
The layout breaks because the ImageViews that you add at the end stretch the columns where they are placed(for example the second ImageView that you add will stretch the TextView that holds the :). You don't say how you want them placed but one simple thing that you could do is to wrap them in another layout, like LinearLayout like this:
<TableRow android:id="#+id/tableRow15" >
<LinearLayout
android:layout_span="6"
android:gravity="center" >
<ImageView
android:id="#+id/imbutt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imbutt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imbutt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_launcher" />
</LinearLayout>
</TableRow>
Of course you could spread them if you want, with the layout_weight attribute.
As a side note, do you really have 6 columns in your layout(you set the layout_span to 6)? Also , do you use those empty singular TextViews or you just use them as dividers(if this is what you want, then you could consider a simple View element outside the TableRows with the desired height)?
Related
i have this xml i haded for each column i want a table layout and a table row, but i cant align the columns i tried put android:layout_weight but id doesn alin the right way can anyone help me.
output for example:
xxxxxx 11111 11111 11111
xml ;
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TableRow>
<TextView
android:id="#+id/id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="#+id/id_instit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="#+id/descricao"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="6dip"
android:paddingTop="6dip"
android:textSize="17dip"
android:textStyle="bold"
/>
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TableRow>
<TextView
android:id="#+id/data"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="6dip"
android:paddingTop="6dip"
android:textSize="17dip"
android:textStyle="bold" />
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TableRow>
<TextView
android:id="#+id/data2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="6dip"
android:paddingTop="6dip"
android:textSize="17dip"
android:textStyle="bold" />
</TableRow>
</TableLayout>
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TableRow>
<TextView
android:id="#+id/qtd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="6dip"
android:paddingTop="6dip"
android:textSize="17dip"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</TableRow>
</TableLayout>
Hope this will help you...
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="4"
android:gravity="center"
android:text="My Report view"
android:textSize="18dp"
android:textStyle="bold" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TextView2"
android:text="" >
</TextView>
<TextView
android:id="#+id/TextView2"
android:gravity="center"
android:text="M"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="#+id/TextView3"
android:gravity="center"
android:text="T"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="#+id/TextView4"
android:gravity="center"
android:text="W"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="#+id/TextView5"
android:gravity="center"
android:text="T"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
<TextView
android:id="#+id/textView6"
android:gravity="center"
android:text="F"
android:textStyle="bold"
android:typeface="serif" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView7"
android:text="Day High"
android:textStyle="bold" >
</TextView>
<TextView
android:id="#+id/textView8"
android:gravity="center_horizontal"
android:text="xxxxx" >
</TextView>
<TextView
android:id="#+id/textView9"
android:gravity="center_horizontal"
android:text="11111" >
</TextView>
<TextView
android:id="#+id/textView10"
android:gravity="center_horizontal"
android:text="34°C" >
</TextView>
<TextView
android:id="#+id/textView11"
android:gravity="center_horizontal"
android:text="11111" >
</TextView>
<TextView
android:id="#+id/textView12"
android:gravity="center_horizontal"
android:text="11111" >
</TextView>
</TableRow>
</TableLayout>
for the previous answer if this is your problem use android:strechColumns="index_of_your_column" to solve it.
when you use TableLayout the width of a column is the width of largest element among all the rows of the table.
here is the example of code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text2"/>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text3"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text4"/>
</TableRow>
</TableLayout>
notice that the remaining unused width is distributed on the last column. if you want to distribute remaining unused space equally among all columns use android:strechColumns="*" inside TableLayout declaration
I am new to android. I am creating following layout design in android. but it not adapt to all type of screen resolution on different mobile device such as Nexus 4,Nexus 7, 3.2in HVGA slider(ADP1). The layout of the screen is changes. how to solve the problem. This is my layout code..
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#drawable/home" android:layout_height="match_parent"
android:orientation="vertical">
<TableRow android:id="#+id/tableRow4" android:padding="20dp" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:text="USER LOGIN" android:textColor="#0000ff" android:textStyle="bold" android:paddingLeft="30dp" android:textSize="32dp" android:id="#+id/textView4" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</TableRow>
<TableRow android:id="#+id/tableRow1" android:padding="5dp" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:text="NAME" android:textColor="#ff0000" android:textStyle="bold" android:textSize="24dp" android:paddingRight="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:text=" " android:id="#+id/loginnew_name_editText1" android:layout_width="fill_parent" android:layout_height="wrap_content"></EditText>
</TableRow>
<TableRow android:id="#+id/tableRow1" android:padding="5dp" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:text="AGE " android:textColor="#ff0000" android:textStyle="bold" android:textSize="24dp" android:paddingRight="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:text=" " android:id="#+id/loginnew_age_editText2" android:layout_width="fill_parent" android:layout_height="wrap_content"></EditText>
</TableRow>
<RelativeLayout android:layout_width="match_parent" android:id="#+id/relativeLayout1" android:layout_height="wrap_content">
<TextView android:text="GENDER" android:textColor="#ff0000" android:textStyle="bold" android:paddingRight="5dp" android:textSize="24dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<RadioGroup android:id="#+id/radioGroup1" android:paddingLeft="100dp" android:layout_width="wrap_content" android:layout_height="wrap_content">
<RadioButton android:layout_height="wrap_content" android:textColor="#ff0000" android:layout_width="wrap_content" android:id="#+id/loginnew_male_radio0" android:checked="true"></RadioButton>
<RadioButton android:layout_height="wrap_content" android:textColor="#ff0000" android:layout_width="wrap_content" android:id="#+id/loginnew_female_radio1"></RadioButton>
</RadioGroup>
<ImageView android:id="#+id/imageView1" android:layout_width="wrap_content" android:padding="5dp" android:layout_height="wrap_content" android:src="#drawable/ast" android:layout_toRightOf="#+id/radioGroup1" android:layout_alignTop="#+id/radioGroup1"></ImageView>
<ImageView android:id="#+id/imageView2" android:layout_width="wrap_content" android:padding="5dp" android:layout_height="wrap_content" android:src="#drawable/dora" android:layout_below="#+id/imageView1" android:layout_alignLeft="#+id/imageView1" android:layout_alignRight="#+id/imageView1"></ImageView>
</RelativeLayout>
<TableRow android:layout_height="wrap_content" android:paddingLeft="20dp" android:paddingRight="20dp" android:layout_alignParentBottom="true" android:id="#+id/tableRow1" android:layout_width="fill_parent">
<Button android:text="SAVE" android:id="#+id/loginnew_save_button1" android:textStyle="bold" android:background="#drawable/brand_button_bg" android:textColor="#ffffff00" android:textSize="28dp" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
</TableRow>
</LinearLayout>
Here is my code :
What i want is just to make scrollbar available in my application so that the overflow text
will be present in the screen.
Here i am using table layout and table row where my content is too long for a row and it will be long for height of screen so how to display horizontal and vertical scrollbar this code is not working
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbars="horizontal|vertical" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
<TextView
android:id="#+id/txtHeaderModels"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:gravity="center_horizontal"
android:text="Demo"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="8pt" />
</TableRow>
</TableLayout>
You can try enclosing within both the scrolls like this,
<ScrollView>
<HorizontalScrollView>
<TableLayout>
<TableRow>
//Your Elements Here
</TableRow>
<TableLayout>
</HorizontalScrollView>
</ScrollView>
Use ScrollView. Here is the Reference link. ScrollView
Tutorial Here - http://www.vogella.de/articles/Android/article.html#scrollview
put your table layout inside a Horizontal Scroll view
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="horizontal">
</ScrollView>
I'm trying to put a TextView into my TableView so that it doesn't push the spinner box and the other TextView off of the screen. I've tried changing the layout_width, yet that has not worked. I have also tried changing the layout_width of the TableRow, but that is not working, either. So how can I fit the text of the left-most textView in the row?
<TableLayout android:id="#+id/abilityScoreTable"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" android:padding="0dip">
<TextView android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="wrap_content" android:gravity="center" android:textSize="30dip" android:id="#+id/abilityScoreBannerText" android:text="Ability Scores"></TextView>
<TableRow android:layout_width="wrap_content" android:gravity="center" android:id="#+id/tableRow1" android:layout_height="wrap_content">
<TextView android:text="zero" android:id="#+id/StrengthBonusText" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<Spinner android:id="#+id/StrengthSpinner" android:layout_width="10px" android:layout_height="wrap_content" android:entries="#array/string_ability_scores"></Spinner>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" android:id="#+id/StrengthTextView" android:text="Strength"
android:textSize="30dip"></TextView>
</TableRow>
<TableRow android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/tableRow2" android:gravity="center">
<Spinner android:layout_height="wrap_content" android:layout_width="wrap_content"
android:id="#+id/dexteritySpinner" android:entries="#array/string_ability_scores"></Spinner>
<TextView android:id="#+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Dexterity" android:textSize="30dip"></TextView>
</TableRow>
<TableRow android:layout_width="wrap_content" android:layout_height="wrap_content"
android:entries="#array/string_ability_scores" android:layout_gravity="center"
android:gravity="center" android:id="#+id/TableRow3">
<Spinner android:id="#+id/ConstitutionSpinner"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:entries="#array/string_ability_scores"></Spinner>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Constitution" android:textSize="30dip"
android:id="#+id/ConstitutionTextView"></TextView>
</TableRow>
<TableRow android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/tableRow3" android:gravity="center">
<Spinner android:layout_height="wrap_content"
android:id="#+id/intelligenceSpinner"
android:layout_width="wrap_content"
android:entries="#array/string_ability_scores"></Spinner>
<TextView android:id="#+id/textView1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Intelligence" android:textSize="30dip"></TextView>
</TableRow>
<TableRow android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/tableRow4"
android:gravity="center">
<Spinner android:layout_height="wrap_content"
android:id="#+id/WisdomSpinner" android:layout_width="wrap_content"
android:entries="#array/string_ability_scores"></Spinner>
<TextView android:id="#+id/textView3"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" android:text="Wisdom"
android:textSize="30dip"></TextView>
</TableRow>
<TableRow android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="#+id/tableRow5"
android:gravity="center">
<Spinner android:layout_height="wrap_content"
android:id="#+id/CharismaSpinner" android:layout_width="wrap_content"
android:entries="#array/string_ability_scores"></Spinner>
<TextView android:id="#+id/textView4"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Charisma" android:textSize="30dip"></TextView>
</TableRow>
</TableLayout>
Currently, it looks like this:
On the top-most spinner there's suppose to be a number to the left. I'm trying to squeeze it on to the screen and have all three fit.
im not sure what you want any way check this and tell me is this what you are trying.
if so here is the xml.
<TableRow android:id="#+id/tableRow1">
<TextView android:text="zero" android:id="#+id/StrengthBonusText"></TextView>
<Spinner android:id="#+id/StrengthSpinner" />
<TextView android:id="#+id/StrengthTextView"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Strength" android:textSize="30dip" />
</TableRow>
<TableRow android:id="#+id/tableRow2">
<View android:visibility="invisible" android:layout_height="0dip" />
<Spinner android:id="#+id/dexteritySpinner" />
<TextView android:id="#+id/textView2" android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Dexterity" android:textSize="30dip" />
</TableRow>
<TableRow android:id="#+id/TableRow3">
<View android:visibility="invisible" android:layout_height="0dip" />
<Spinner android:id="#+id/ConstitutionSpinner"></Spinner>
<TextView android:id="#+id/ConstitutionTextView"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Constitution" android:textSize="30dip"></TextView>
</TableRow>
<TableRow android:id="#+id/tableRow3">
<View android:visibility="invisible" android:layout_height="0dip"/>
<Spinner android:id="#+id/intelligenceSpinner"></Spinner>
<TextView android:id="#+id/textView1" android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Intelligence" android:textSize="30dip"></TextView>
</TableRow>
<TableRow android:id="#+id/tableRow4">
<View android:visibility="invisible" android:layout_height="0dip"/>
<Spinner android:id="#+id/WisdomSpinner"></Spinner>
<TextView android:id="#+id/textView3" android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Wisdom" android:textSize="30dip"></TextView>
</TableRow>
<TableRow android:id="#+id/tableRow5">
<View android:visibility="invisible" android:layout_height="0dip"/>
<Spinner android:id="#+id/CharismaSpinner"></Spinner>
<TextView android:id="#+id/textView4" android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Charisma" android:textSize="30dip"></TextView>
</TableRow>
Have you tried using a relative layout or is that just not an option? Also I noticed you are mixing px and dip - this is usually not recommended
If i use this layout, everything is ok
See this Image:
<TableLayout android:id="#+id/TableLayout01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#000000" android:layout_margin="10dip" android:padding="10dip" >
<TableRow android:id="#+id/row1" android:layout_width="wrap_content" android:layout_height="wrap_content" >
<TextView android:id="#+id/n1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:text="aaaaa a aaaaaaaaa:"></TextView>
<TextView android:id="#+id/c1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:layout_column="3" android:text="15"></TextView>
</TableRow>
<TableRow android:id="#+id/row2" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="#+id/n2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:text="aaaaaaa aaaaa:"></TextView>
<TextView android:id="#+id/c2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:layout_column="3" android:text="12"></TextView>
</TableRow>
<TableRow android:id="#+id/row3" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="#+id/n3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:text="aaa:"></TextView>
<TextView android:id="#+id/c3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:layout_column="3" android:text="14"></TextView>
</TableRow>
<TableRow android:id="#+id/row4" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="#+id/n4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:text="aaa:"></TextView>
<TextView android:id="#+id/c4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:layout_column="3" android:text="18"></TextView>
</TableRow>
<TableRow android:id="#+id/row5" android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView android:id="#+id/n5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:text="aaaaaa aaaaaaaa:"></TextView>
<TextView android:id="#+id/c5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ffffff" android:layout_column="2" android:text="70"></TextView>
</TableRow>
</TableLayout>
But if i set android:layout_column="3" for the second textview in the last row, this shows http://www.lukafinzgar.com/nekul.png .
How should i set the attributes to get all the numbers in the third column?
You have to use "android:layout_width" and "android:layout_height" in TableLayout tag only. not anywhere else. And use "android:layout_weight" in each element of TableRow tag to adjust the columns horizontally.Try the below coding.
<TableLayout android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow>
<TextView android:id="#+id/cpotl1textview1"
android:layout_weight="0.5"
android:text="Total Outstanding" />
<EditText android:id="#+id/cpotl1edittext1"
android:layout_weight="0.5"
android:inputType="numberDecimal" />
</TableRow>
<TableRow>
<TextView android:id="#+id/cpotl1textview2"
android:layout_weight="0.5"
android:text="Claim Amount" />
<EditText android:id="#+id/cpotl1edittext2"
android:layout_weight="0.5"
android:inputType="numberDecimal" />
</TableRow>
<TableRow>
<TextView android:id="#+id/cpotl1textview3"
android:layout_weight="0.5"
android:text="Select Message" />
<AutoCompleteTextView android:id="#+id/cpotl1autocompletetextview"
android:layout_weight="0.5"
android:hint="Templates" />
</TableRow>
</TableLayout>
Thanks for opportunity.
Try This:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:background="#000000"
android:padding="10dip" >
<TableRow
android:id="#+id/row1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/n1"
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaa a aaaaaaaaa:"
android:textColor="#ffffff" >
</TextView>
<TextView
android:id="#+id/c1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:text="15"
android:textColor="#ffffff" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/row2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/n2"
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaaa aaaaa:"
android:textColor="#ffffff" >
</TextView>
<TextView
android:id="#+id/c2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:text="12"
android:textColor="#ffffff" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/row3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/n3"
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaa:"
android:textColor="#ffffff" >
</TextView>
<TextView
android:id="#+id/c3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:text="14"
android:textColor="#ffffff" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/row4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/n4"
android:layout_width="wrap_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaa:"
android:textColor="#ffffff" >
</TextView>
<TextView
android:id="#+id/c4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:text="18"
android:textColor="#ffffff" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/row5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/n5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="aaaaaa aaarrrrrrraaaaa:"
android:textColor="#ffffff" >
</TextView>
<TextView
android:id="#+id/c5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="3"
android:text="70"
android:textColor="#ffffff" >
</TextView>
</TableRow>
</TableLayout>