align list items of listview in 4 columns - android

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

Related

Android: textViews now visible in activity?

Within my Android Activity I am attempting to add two textviews at the bottom of the screen, not within the table.
However, within my activity they are not visible. They are definitely declared correctly in the corresponding activty. What is the error within my XML code below?
XML code:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/TableLayout03"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="#+id/TableRow04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<Spinner
android:id="#+id/Spinner01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</Spinner>
</TableRow>
<TableRow
android:id="#+id/TableRow05"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10sp" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/TableRow01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<TextView
android:id="#+id/mainTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="20sp"
android:text="Memory Game"
android:textColor="#EEFFAA"
android:textSize="30sp"
android:visibility="visible" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/TableRow02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="#+id/myWebSite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:bufferType="normal"
android:gravity="center"
android:text="http://www.aviyehuda.com"
android:textColor="#FFEEAA"
android:typeface="normal" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/TableRow03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/card1" >
</ImageView>
</LinearLayout>
<TextView
android:id="#+id/tvSeeMeditation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:textSize="25dp"
android:paddingBottom="3dp"/>
<TextView
android:id="#+id/tvSeeAttention"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:textSize="25dp" />
</TableRow>
</TableLayout>
EDIT (2nd attempt-still not visible)
<?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"
android:padding="15dp" >
<TableLayout
android:id="#+id/TableLayout03"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="#+id/TableRow04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<Spinner
android:id="#+id/Spinner01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</Spinner>
</TableRow>
<TableRow
android:id="#+id/TableRow05"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10sp" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/TableRow01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<TextView
android:id="#+id/mainTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="20sp"
android:text="Memory Game"
android:textColor="#EEFFAA"
android:textSize="30sp"
android:visibility="visible" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/TableRow02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<TextView
android:id="#+id/myWebSite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:bufferType="normal"
android:gravity="center"
android:text="http://www.aviyehuda.com"
android:textColor="#FFEEAA"
android:typeface="normal" >
</TextView>
</TableRow>
<TableRow
android:id="#+id/TableRow03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<LinearLayout
android:id="#+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<ImageView
android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/card1" >
</ImageView>
</LinearLayout>
</TableRow>
</TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="15dp" >
<TextView
android:id="#+id/tvSeeMeditation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:textSize="25dp"
android:paddingBottom="3dp"/>
<TextView
android:id="#+id/tvSeeAttention"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:textSize="25dp" />
</LinearLayout>
</LinearLayout>
They are visible add some text to them and you will see them in your UI. Also in order to add some UI element to bottom of the screen you should use something like this;
<RelativeLayout >
<TableLayout></TableLayout>
<TextView
android:id="#+id/tvSeeAttention"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:textSize="25dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
else your textviews will be at the end of your table not at the bottom of the screen.
EDIT: Your table layout;
after changing it as android:layout_height="wrap_content"
Give some value of android:text to every textview in yor xml file(say it anything like "tv1" and so on) and then check that whether or not they are not placed inside your table layout.Because there are textviews with empty android:text in your file and you may not be able to see there position on the screen

ScrollView inside TableLayout in android

I am developing an application in which I am using a Table Layout. The first row of my table layout is as Header. Now I want something that the Header or first row should not be scrollable and other should be scrollable. My code is :
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*" android:stretchColumns="*" android:background="#ffffff">
<!-- Row 1 with single column -->
<TableRow
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18sp" android:text="#string/com" android:layout_span="3"
android:padding="18dip" android:gravity="center"
android:textColor="#000"/>
</TableRow>
<!-- Row 2 with 3 columns -->
<TableRow
android:id="#+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#b0b0b0"
android:gravity="center_horizontal">
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="#string/c"
android:gravity="center"
android:textSize="18sp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/TextView3"
android:text="#string/c1"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:id="#+id/TextView4"
android:text="#string/c2"
android:layout_weight="1"
android:gravity="center"/>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#b0b0b0"
android:gravity="center_horizontal">
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="#string/d"
android:gravity="center"
android:textSize="18sp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<!-- Row 3 with 2 columns -->
<TableRow
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/TextView6"
android:text="#string/d1"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:id="#+id/TextView7"
android:text="#string/d2"
android:layout_weight="1"
android:gravity="center"/>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#b0b0b0"
android:gravity="center_horizontal">
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="#string/e"
android:gravity="center"
android:textSize="18sp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
<!-- Row 3 with 2 columns -->
<TableRow
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal">
<TextView
android:id="#+id/TextView6"
android:text="#string/e1"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:id="#+id/TextView7"
android:text="#string/e2"
android:layout_weight="1"
android:gravity="center"/>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#b0b0b0"
android:gravity="center_horizontal">
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="#string/g"
android:gravity="center"
android:textSize="18sp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</TableRow>
</TableLayout>
Can anybody please help me how to make first TextView as header and non-scrollable and other complete table as scrollable ..??
simple use this code in xml file its work...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<!-- Header aligned to top -->
<LinearLayout
android:id="#+id/headerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:shrinkColumns="*"
android:stretchColumns="*" >
<!-- Row 1 with single column -->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="3"
android:gravity="center"
android:padding="18dip"
android:text="com"
android:textColor="#000"
android:textSize="18sp" />
</TableRow>
</TableLayout>
</LinearLayout>
<ScrollView
android:id="#+id/scrollablContent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:shrinkColumns="*"
android:stretchColumns="*" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b0b0b0"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="c"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/TextView3"
android:layout_weight="1"
android:gravity="center"
android:text="c1" />
<TextView
android:id="#+id/TextView4"
android:layout_weight="1"
android:gravity="center"
android:text="c2" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b0b0b0"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="d"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
</TableRow>
<!-- Row 3 with 2 columns -->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/TextView6"
android:layout_weight="1"
android:gravity="center"
android:text="d1" />
<TextView
android:id="#+id/TextView7"
android:layout_weight="1"
android:gravity="center"
android:text="d2" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b0b0b0"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="e"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
</TableRow>
<!-- Row 3 with 2 columns -->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/TextView6"
android:layout_weight="1"
android:gravity="center"
android:text="e1" />
<TextView
android:id="#+id/TextView7"
android:layout_weight="1"
android:gravity="center"
android:text="e2" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b0b0b0"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="g"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
</TableRow>
</TableLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/footerView"
android:layout_width="wrap_content"
android:layout_height="72dp" >
<!-- Footer aligned to bottom -->
</RelativeLayout>
</LinearLayout>
Try some thing like this,
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*" android:stretchColumns="*" android:background="#ffffff">
<TableRow
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal">
<TextView
android:layout_width="match_parent" android:layout_height="wrap_content"
android:textSize="18sp" android:text="#string/com" android:layout_span="3"
android:padding="18dip" android:gravity="center"
android:textColor="#000"/>
</TableRow>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b0b0b0"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="#string/c"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/TextView3"
android:layout_weight="1"
android:gravity="center"
android:text="#string/c1" />
<TextView
android:id="#+id/TextView4"
android:layout_weight="1"
android:gravity="center"
android:text="#string/c2" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b0b0b0"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="#string/d"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/TextView6"
android:layout_weight="1"
android:gravity="center"
android:text="#string/d1" />
<TextView
android:id="#+id/TextView7"
android:layout_weight="1"
android:gravity="center"
android:text="#string/d2" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b0b0b0"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="#string/e"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/TextView6"
android:layout_weight="1"
android:gravity="center"
android:text="#string/e1" />
<TextView
android:id="#+id/TextView7"
android:layout_weight="1"
android:gravity="center"
android:text="#string/e2" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#b0b0b0"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center"
android:text="#string/g"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textSize="18sp" />
</TableRow>
</LinearLayout>
</ScrollView>
</TableLayout>
After your First row , describe the scrollview
like this...
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</TableRow>
</LinearLayout>
</ScrollView>
</TableLayout>
You can create a LinearLayout for remaining table rows except header table row and add this LinearLayout to ScrollView, because ScrollView can have only one child.
Eg:
<ScrollView
android:id="#+id/scrollviewID"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
//your table rows
</LinearLayout>
</ScrollView>

android design xml layout alignment (how to draw the like that)

How to design the following as shown in the picture:
my xml structure is:
<Root>
<other design>
<need to design as in picture>
</Root>
the picture is :
that is the text should appear in left and right alignment.
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="HOUR"
android:textColor="#C0C0C0" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="$1.80"
android:textColor="#6686A8" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="DAY"
android:textColor="#C0C0C0" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="$10.00"
android:textColor="#6686A8" />
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="WEEK"
android:textColor="#C0C0C0" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="$35.00"
android:textColor="#6686A8" />
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="MONTH"
android:textColor="#C0C0C0" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="$105.00"
android:textColor="#6686A8" />
</TableRow>
</TableLayout>
You can use TableLayout to achieve that kind of layout.

table layout inside relative layout

is it possible to use table layout in relative layout. for example:
in main.xml:
< RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:id="#+id/tableRow4"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18dp"
android:text="Weather Table"
android:gravity="center"> < /TextView>
</ TableRow>
</ TableLayout>
</ RelativeLayout>
how can i use two type of layout in single xml file.
1-Delete namespace that you assigned to TableLayout("http://schemas.android.com/apk/res/android").It would be seems as:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:id="#+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="#+id/tableRow4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Weather Table"
android:textSize="18dp" >
</TextView>
</TableRow>
</TableLayout>
</RelativeLayout>
2-Your tags has incorrect blank spaces,for example </ TableRow>.Use </TableRow> instead of it.
I am never using this but this is helps you.
make drawable/table_shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape= "rectangle" >
<solid android:color="#000"/>
<stroke android:width="1dp" android:color="#ff9"/>
</shape>
layout/my_table.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow android:id="#+id/tabla_cabecera" android:layout_width="match_parent" android:layout_height="match_parent"></TableRow>
<TableLayout android:id="#+id/tabla_cuerpo" android:layout_height="match_parent" android:layout_width="match_parent">
<TableRow android:id="#+id/tableRow1" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:background="#drawable/cell_shape" android:padding="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
<TextView android:background="#drawable/cell_shape" android:padding="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
<TextView android:background="#drawable/cell_shape" android:padding="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
</TableRow>
<TableRow android:id="#+id/tableRow2" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:background="#drawable/cell_shape" android:padding="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
<TextView android:background="#drawable/cell_shape" android:padding="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
<TextView android:background="#drawable/cell_shape" android:padding="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView></TableRow>
<TableRow android:id="#+id/tableRow3" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:background="#drawable/cell_shape" android:padding="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
<TextView android:background="#drawable/cell_shape" android:padding="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
<TextView android:background="#drawable/cell_shape" android:padding="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
</TableRow>
<TableRow android:id="#+id/tableRow4" android:layout_width="match_parent" android:layout_height="wrap_content">
<TextView android:background="#drawable/cell_shape" android:padding="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
<TextView android:background="#drawable/cell_shape" android:padding="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
<TextView android:background="#drawable/cell_shape" android:padding="5dp" android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:text="TextView"></TextView>
</TableRow>
</TableLayout>
</RelativeLayout>
I have very recently done this, here is the code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TableLayout android:layout_width="fill_parent" android:id="#+id/tl"
android:layout_height="match_parent">
<TableRow>
<Button
android:id="#+id/Bkanban"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/left_arrow" />
<EditText
android:id="#+id/ETnew_task"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="500"
android:inputType="text"
android:hint="#string/to_do"
/>
<Button
android:id="#+id/Bplus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="right"
android:text="+"></Button>
</TableRow>
</TableLayout>

How can I solve not selecting total listview when I scroll list page?

I have a listview in my application. I have 5 columns in my listview and items are displayed dynamically. The problem is when I scroll my list the total list selected and the background of the listpage will be changed as black color.
Here my code is:
<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/bg">
<TableRow
android:id="#+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/t1"
android:text="Tname"
android:typeface="serif"
android:padding="3dip"
android:textColor="#9400D3">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/t2"
android:text="From"
android:textColor="#9400D3"
android:typeface="serif"
>
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/t3"
android:text="Arrival"
android:textColor="#9400D3"
android:typeface="serif"
>
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/t4"
android:text="To"
android:textColor="#9400D3"
android:typeface="serif">
</TextView>
<TextView
android:id="#+id/t5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Departure"
android:textColor="#9400D3"
android:typeface="serif"
>
</TextView>
</TableRow>
<ListView
android:id="#id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="10px"
android:dividerHeight="1px"
android:paddingLeft="0px"
android:focusable="false">
</ListView>
</TableLayout>
my items listpage
<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:focusableInTouchMode="false" >
<TableRow
android:id="#+id/tableRow1"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/train"
android:text="train"
android:textColor="#FF0000"
android:typeface="serif"
android:padding="3dip"
>
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/from"
android:text="From"
android:textColor="#292421"
android:typeface="serif"
>
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/arr"
android:text="arr"
android:textColor="#000080"
android:typeface="serif"
>
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/to"
android:text="to"
android:textColor="#292421"
android:typeface="serif"
>
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/dep"
android:text="Location"
android:textColor="#000080"
android:typeface="serif"
></TextView>
</TableRow>
</TableLayout>
Please, tell me where I have done wrong..
set cacheColorHint="#00000000" in Listview property

Categories

Resources