开发者

how to design a table in android

开发者 https://www.devze.com 2023-03-15 00:59 出处:网络
in my app i need to design like the following image i use table layout for this but i get like follwing:

in my app i need to design like the following image

how to design a table in android

i use table layout for this but i get like follwing:

TextViewTextViewTextView .....

mycode:

   ....... 
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/tableLayout1">
<TableRow android:id="@+id/tableRow1" android:layout_width="fill_parent"开发者_StackOverflow
    android:layout_height="wrap_content">
    <TextView android:layout_width="fill_parent" android:text="Your State"
       android:layout_gravity="left" android:id="@+id/textView1"
       android:layout_height="wrap_content">
    </TextView>
    <TextView android:layout_width="wrap_content" android:text="Your State"
       android:layout_gravity="left" android:id="@+id/textView1"
       android:layout_height="wrap_content">
    </TextView>
</TableRow>
     .........

my design is not shown as above image. i do not know how to design exact the above image. please help me


Xml file:

<?xml version="1.0" encoding="utf-8"? >
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">

<TableRow android:layout_width="match_parent"
    android:weightSum="1"
    android:layout_height="wrap_content">
    <TextView
        android:background="@drawable/shape_edittext"
     android:layout_weight="0.2"
     android:layout_width="0dp"
     android:layout_height="match_parent"
        android:text="Save As..."
        android:padding="3dip" />

    <TextView
        android:background="@drawable/shape_edittext"
        android:layout_weight="0.8"
     android:layout_width="0dp"

        android:padding="3dip"
        android:text="Ctrl-Oda asd dfgd df gdfgd gdf dfg dfgd df g  d a asda dsadasd ada das sad adas  das dsa dsda asd asd  sad a dad" />


</TableRow>


</TableLayout>

======================

drawable file

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"    
android:shape="rectangle">
<gradient
    android:startColor="#FFFFFF"
    android:endColor="#FFFFFF"
    android:angle="45"/>
<padding android:left="8dp"
    android:top="8dp"
    android:right="8dp"
    android:bottom="8dp" />
<corners android:radius="0dp" />
<stroke android:width="1dp" android:color="#FF0000"/>
<solid android:color="@android:color/darker_gray"/>
</shape>


You should have six tablerows intable layout and each tablerow whould consists of four textviews.

See the Sample Code

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TableRow>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:textColor="#ffffff"
            android:textStyle="bold" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Password:"
            android:textColor="#ffffff"
            android:textStyle="bold" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pas111"
            android:textColor="#ffffff"
            android:textStyle="bold" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pas111"
            android:textColor="#ffffff"
            android:textStyle="bold" />
    </TableRow>

    <TableRow>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Password"
            android:textColor="#ffffff"
            android:textStyle="bold" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pas111"
            android:textColor="#ffffff"
            android:textStyle="bold" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pas111"
            android:textColor="#ffffff"
            android:textStyle="bold" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pas111"
            android:textColor="#ffffff"
            android:textStyle="bold" />
    </TableRow>
</TableLayout>


try experimenting with "android:stretchColumns"


  android:background="@android:drawable/btn_default_small"

put this tag in textViews and tableLayout u have.. in xml.. u cantry giving other values like "editbox_background" etc..


Make Table using HTML/CSS. The table would be made easily and much more beautiful. Use WebView to access the HTML file of table. Save html file in the assets folder. For more details google how to implement HTML file in Android.

0

精彩评论

暂无评论...
验证码 换一张
取 消