【问题标题】:how to design a table in android如何在android中设计一个表格
【发布时间】:2015-07-30 02:17:27
【问题描述】:

在我的应用程序中,我需要设计如下图

我为此使用表格布局,但我得到如下所示:

TextViewTextViewTextView .....

我的代码:

   ....... 
<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"
    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>
     .........

我的设计未如上图所示。我不知道如何精确地设计上面的图像。请帮帮我

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    Xml 文件:

    <?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>
    

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

    可绘制文件

    <?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>
    

    【讨论】:

      【解决方案2】:

      您应该有六个表格行 intable 布局,每个表格行由四个文本视图组成。

      查看示例代码

      <?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>
      

      【讨论】:

        【解决方案3】:

        尝试使用“android:stretchColumns”

        【讨论】:

          【解决方案4】:
            android:background="@android:drawable/btn_default_small"
          

          把这个标签放在你有的textViews和tableLayout中..在xml中..你可以尝试给其他值,比如"editbox_background"等..

          【讨论】:

          • 我使用你的代码。如果我给出如图所示的长文​​本,它不会出现在多行中,尽管给出以下 android:maxLines="3" android:text="Without Swimming pool cover"。如何在多行中获取长文本
          • 设置 android:singleline="false"
          • android:singleLine="false" 它不起作用。仍然出现在单行中,以便隐藏其他文本视图。
          【解决方案5】:

          使用 HTML/CSS 制作表格。这张桌子会很容易制作,而且更漂亮。使用 WebView 访问表格的 HTML 文件。将 html 文件保存在 assets 文件夹中。 更多细节谷歌如何在 Android 中实现 HTML 文件。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2012-12-16
            • 2015-07-06
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多