简体   繁体   English

如何在FrameLayout中心设置图像

[英]How to set image on centre in FrameLayout

I'm doing a project in which I want to set an image in the center.I'm using TableLayout and I want set this image in FrameLayout. 我正在做一个项目,我想在中心设置一个图像。我正在使用TableLayout,我想在FrameLayout中设置这个图像。 If u have any idea so please suggest me. 如果您有任何想法,请建议我。 Its very urgent. 这非常紧迫。 Thanx to all. 对所有人而言。 Here is my code: 这是我的代码:

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

Use this line in your Frame layout: 在Frame布局中使用此行:

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

我通过添加到Child (框架布局内部的东西)实现了它

  android:layout_gravity="center" 

Did you try this: 你试过这个:

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

where bg is an image in the drawable-hdpi/drawable-mdpi etc.It can be bg.png/bg.jpg etc. 其中bg是drawable-hdpi / drawable-mdpi等中的图像。它可以是bg.png / bg.jpg等。

If you want to set the image inside the framLayout in the center,then try like the following. 如果要在中心的framLayout中设置图像,请尝试以下操作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM