Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在FrameLayout中将图像设置在中心_Android - Fatal编程技术网

Android 如何在FrameLayout中将图像设置在中心

Android 如何在FrameLayout中将图像设置在中心,android,Android,我正在做一个项目,我想在中心设置一个图像。我正在使用TableLayout,我想在FrameLayout中设置这个图像。如果你有任何想法,请建议我。非常紧急。谢谢大家。这是我的密码: <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="match_parent" android:sh

我正在做一个项目,我想在中心设置一个图像。我正在使用TableLayout,我想在FrameLayout中设置这个图像。如果你有任何想法,请建议我。非常紧急。谢谢大家。这是我的密码:

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*" >

       <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
         android:layout_weight="1"
          android:layout_gravity="center"
          android:scaleType="center"
         >

        <com.nexbits.digitechi.DrawCanvas
        android:id="@+id/SurfaceView"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

         />


     </FrameLayout>

     <TableRow

     android:layout_height="wrap_content"
     android:layout_width="fill_parent"
     android:gravity="center_horizontal">


    <ImageButton
        android:id="@+id/imageButton5"

        android:layout_weight="1"
        android:padding="20dip"
        android:layout_gravity="center_horizontal"
        android:onClick="video"
        android:src="@drawable/ic_webcamera" />

    <ImageButton
         android:id="@+id/imageButton3"
         android:layout_weight="1"
         android:layout_gravity="center_horizontal"

         android:padding="20dip"
         android:src="@drawable/ic_twitter64" />

    <ImageButton
        android:id="@+id/imageButton2"

         android:layout_weight="1"
         android:padding="20dip"
         android:layout_gravity="center_horizontal"

         android:src="@drawable/ic_brightness64" />

      <ImageButton
          android:id="@+id/imageButton4"
          android:layout_weight="1"
          android:padding="20dip"
          android:layout_gravity="center_horizontal"
          android:src="@drawable/microscope" />
         </TableRow>
         </TableLayout>

在框架布局中使用此行:

android:layout_gravity="center_vertical|center_horizontal"
android:foregroundGravity="center"

<com.nexbits.digitechi.DrawCanvas
    android:id="@+id/SurfaceView"
    android:layout_gravity="center_vertical|center_horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
android:layout\u gravity=“居中垂直|居中水平”
android:foregroundGravity=“center”
您是否尝试过:

<FrameLayout
        android:gravity="center"
        android:background="@drawable/bg"
>

其中bg是可绘制hdpi/可绘制mdpi等中的图像。它可以是bg.png/bg.jpg等

如果要将图像设置在框架布局的中间,请尝试以下操作

    <com.nexbits.digitechi.DrawCanvas
         android:id="@+id/SurfaceView"

         android:layout_width="wrap_content"
         android:gravity="center_vertical" or android:gravity="center_horizontal"

         android:layout_height="wrap_content"

     />


 </FrameLayout>


我通过添加到子项(框架布局中的某些内容)来实现它


FrameLayout没有重力线在FrameLayout中没有任何作用。@Patrick你用android:foregroundGravity试过吗?显示您的代码。@Patrick在您的代码中,您没有为相对布局设置高度和宽度,如果父布局是相对布局,则可以使用布局重力,您需要使用ndroid:layout\u centerInParent=“true”。我不知道你到底面临什么问题。
  android:layout_gravity="center"