【问题标题】:Table layout span issue in androidandroid中的表格布局跨度问题
【发布时间】:2016-03-18 13:43:56
【问题描述】:

我正在使用下面的 xml 文件来绘制添加详细信息表单。

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:focusableInTouchMode="true" 
    android:background="@color/body_background"
    android:paddingBottom="5dp"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="2dp">

    <TableRow>
        <ImageView
            android:id="@+id/product_image"
            android:layout_span="3"
            android:layout_width="wrap_content"
            android:layout_height="120dp"
            android:focusable="false"
            android:src="@drawable/no_image" />

    </TableRow>

    <TableRow>
        <TextView android:text="@string/medicine_name" />
        <EditText
            style="@style/textbox"
            android:id="@+id/txtMedicine"
            android:inputType="text" />
    </TableRow>

    <TableRow>
        <TextView android:text="@string/treatment_for" />
        <EditText
            style="@style/textbox" 
            android:id="@+id/txtTreatmentfor"
            android:inputType="text" />
    </TableRow>

    <TableRow>
        <TextView android:text="@string/side_effects" />
        <EditText 
            style="@style/textbox"
            android:id="@+id/txtSideEffects" 
            android:inputType="text"/>
    </TableRow>

    <TableRow>
        <TextView android:text="@string/price" />
        <EditText 
            style="@style/textbox"
            android:id="@+id/txtPrice" 
            android:inputType="numberDecimal"/>
    </TableRow>

    <TableRow>
        <TextView android:text="@string/storage_specifivation" />
        <EditText 
            style="@style/textbox"
            android:id="@+id/txtStorageSpecification" 
            android:inputType="text"/>
    </TableRow>

    <TableRow>
        <TextView android:text="@string/general_information" />
        <EditText 
            style="@style/textbox"
            android:id="@+id/txtGeneralInformation" 
            android:inputType="text"/>
    </TableRow>

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="wrap_content"
        android:focusable="false" >

        <Button
            android:id="@+id/btnSubmit"
            android:layout_width="wrap_content"
            android:layout_span="2"
            android:text="@string/submit" />
    </TableRow>

</TableLayout>

我得到了输出:

但我希望图像视图跨越两列,并且相同的按钮也适合完整的。

我想像下面这样输出

我缺少什么或 xml 中的问题是什么?

【问题讨论】:

    标签: android xml tablelayout


    【解决方案1】:

    只需在 TableRow 中使用 weightSum 和在 ImageView 中使用 layout_weight 和类似按钮...

    图像视图:

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="1">
        <ImageView
            android:id="@+id/product_image"
            android:layout_width="wrap_content"
            android:layout_height="120dp"
            android:focusable="false"
            android:src="@drawable/no_image"
            android:layout_weight="1" />
    </TableRow>
    

    按钮:

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:focusable="false"
        android:layout_height="wrap_content"
        android:weightSum="1" >
        <Button
            android:id="@+id/btnSubmit"
            android:layout_width="wrap_content"
            android:layout_span="2"
            android:text="dfghdgd"
            android:layout_weight="1" />
    </TableRow>
    

    【讨论】:

      猜你喜欢
      • 2011-02-27
      • 2013-04-28
      • 1970-01-01
      • 2011-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多