Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set image on centre in FrameLayout

Tags:

android

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. 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>
like image 253
dikshantrawal Avatar asked Dec 19 '11 07:12

dikshantrawal


2 Answers

Use this line in your Frame layout:

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" />
like image 177
Padma Kumar Avatar answered Oct 23 '22 19:10

Padma Kumar


I achieved it by adding to Child (something inside frame layout)

  android:layout_gravity="center" 
like image 22
Jakub S. Avatar answered Oct 23 '22 17:10

Jakub S.