Android 将ImageView居中于TableRow内

Android 将ImageView居中于TableRow内,android,android-layout,Android,Android Layout,我在TableLayout(TableRow)中的图像居中有问题。ImageView总是在左边,我需要他居中 以下是XML: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_paren

我在TableLayout(TableRow)中的图像居中有问题。ImageView总是在左边,我需要他居中

以下是XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#fff2d8">

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >
            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:src="@drawable/logo"
                android:id="@+id/imageView"
            />
        </TableRow>
    </TableLayout>

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_margin="10dp"
        android:layout_weight="1">
    <TableRow
          .
          .


您可以将
android:gravity=“center”
添加到TableRow的XML定义中。

您可以将
android:gravity=“center”
添加到TableRow的XML定义中。

像这样更新布局

 <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <TableRow
            android:gravity="center_horizontal|center_vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <ImageView
                android:id="@+id/imageView"
                android:background="@drawable/ic_launcher"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:src="@drawable/logo" />
        </TableRow>
    </TableLayout>

像这样更新布局

 <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <TableRow
            android:gravity="center_horizontal|center_vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <ImageView
                android:id="@+id/imageView"
                android:background="@drawable/ic_launcher"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:src="@drawable/logo" />
        </TableRow>
    </TableLayout>

试试
android:layout\u span=“2”
内置
ImageView

<TableLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center">
            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:src="@drawable/logo"
                android:id="@+id/imageView"
                android:layout_span="2"/>
        </TableRow>
    </TableLayout>

试试
android:layout\u span=“2”
内置
ImageView

<TableLayout
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center">
            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:src="@drawable/logo"
                android:id="@+id/imageView"
                android:layout_span="2"/>
        </TableRow>
    </TableLayout>


这应该是公认的答案。准确地告诉你需要什么,而不是一堆无关的东西。这应该是公认的答案。准确地告诉你需要什么,而不是一堆无关的东西。