1

我有这个滚动视图,里面有Linearlayout,里面还有一个linearlayout。我想以表格形式显示数据。我有一个列表视图,在其中我使用 record.xml 作为列表视图中的单行通过代码推送数据。

我希望在其中显示边距。但他们不工作。它们在 eclipse 中准确显示,但在部署时没有在模拟器 android 2.3 中显示。

帮助。在此先感谢...等待回复...
record.xml:

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="50dp" android:gravity="center_vertical" android:background="#D1EFCD">

    <TextView
        android:id="@+id/serial_no"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="null"
        android:width="100dp"
        android:textAppearance="?android:attr/textAppearanceMedium" android:background="#9EC39A"/>

    <TextView
        android:id="@+id/item_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="null"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:width="100dp" android:background="#9EC39A" android:layout_marginLeft="1dp"/>

    <TextView
        android:id="@+id/wt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="null"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:width="100dp" android:background="#9EC39A" android:layout_marginLeft="1dp"/>

    <TextView
        android:id="@+id/dte"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="null"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:width="100dp" android:background="#9EC39A" android:layout_marginLeft="1dp"/>

    <TextView
        android:id="@+id/amt"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="null"
        android:width="100dp" android:background="#9EC39A" android:layout_marginLeft="1dp"/>

    <TextView
        android:id="@+id/cust_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="null"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:width="100dp" android:background="#9EC39A" android:layout_marginLeft="1dp"/>

    <TextView
        android:id="@+id/rate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="null"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:width="100dp" android:background="#9EC39A" android:layout_marginLeft="1dp"/>

</TableRow>


滚动数据.xml:

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal|vertical"
android:background="#D1EFCD" >
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" android:layout_margin="1dp">

    <TextView
        android:id="@+id/Sr.No."
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Sr.No."
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold"
        android:width="100dp" android:layout_marginTop="2dp" android:layout_marginLeft="2dp" android:background="#9EC39A" android:gravity="center"/>

    <TextView
        android:id="@+id/Item"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Item"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold"
        android:width="100dp" android:layout_marginTop="2dp" android:layout_marginLeft="1dp" android:background="#9EC39A" android:gravity="center"/>

    <TextView
        android:id="@+id/Weight"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Weight"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold"
        android:width="100dp" android:layout_marginTop="2dp" android:layout_marginLeft="1dp" android:background="#9EC39A" android:gravity="center"/>

    <TextView
        android:id="@+id/Date"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Date"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold"
        android:width="100dp" android:layout_marginTop="2dp" android:layout_marginLeft="1dp" android:background="#9EC39A" android:gravity="center"/>

    <TextView
        android:id="@+id/Amount"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Amount"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold"
        android:width="100dp" android:layout_marginTop="2dp" android:layout_marginLeft="1dp" android:background="#9EC39A" android:gravity="center"/>

    <TextView
        android:id="@+id/CustomerName"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Customer Name"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold"
        android:width="100dp" android:layout_marginTop="2dp" android:layout_marginLeft="1dp" android:background="#9EC39A" android:gravity="center"/>

    <TextView
        android:id="@+id/RateofInterest"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="Rate of Interest"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold"
        android:width="100dp" android:layout_marginTop="2dp" android:layout_marginLeft="1dp" android:layout_marginRight="2dp" android:background="#9EC39A" android:gravity="center"/>

    </LinearLayout>
    <ListView
        android:id="@+id/DataRows"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:divider="#D1EFCD"
        android:dividerHeight="1dp" android:layout_marginBottom="2dp" android:layout_marginLeft="2dp" android:layout_marginRight="2dp" android:layout_marginTop="1dp" android:layout_gravity="center">
    </ListView>

</LinearLayout>


</HorizontalScrollView>


模拟器截图 在此处输入图像描述

4

1 回答 1

0

如果您想将数据行文本居中TextViews,就像标题一样,只需在您的 android:gravity="center" 中添加TextViews,如下所示:

<?xml version="1.0" encoding="utf-8"?>

<TextView
    android:id="@+id/serial_no"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#9EC39A"
    android:gravity="center"
    android:text="123"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:width="100dp" />

<TextView
    android:id="@+id/item_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="1dp"
    android:background="#9EC39A"
    android:gravity="center"
    android:text="asf"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:width="100dp" />

<TextView
    android:id="@+id/wt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="1dp"
    android:background="#9EC39A"
    android:gravity="center"
    android:text="sadasd"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:width="100dp" />

<TextView
    android:id="@+id/dte"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="1dp"
    android:background="#9EC39A"
    android:gravity="center"
    android:text="23"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:width="100dp" />

<TextView
    android:id="@+id/amt"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="1dp"
    android:background="#9EC39A"
    android:gravity="center"
    android:text="null"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:width="100dp" />

<TextView
    android:id="@+id/cust_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="1dp"
    android:background="#9EC39A"
    android:gravity="center"
    android:text="null"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:width="100dp" />

<TextView
    android:id="@+id/rate"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="1dp"
    android:background="#9EC39A"
    android:gravity="center"
    android:text="null"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:width="100dp" />

这将使您的数据与您的标题保持一致。

于 2014-07-19T01:54:23.270 回答