Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android align image in top and center in RelativeLayout

I'm trying to align image to top of my Relative Layout and after that center it horizontally. Here is the code I'm using for :

<ImageView  
        android:id="@+id/collection_image_background"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"  />

,but this code is not working. My image is centered,but not aligned at top of my Relative Layout. I tried with android:scaleType="fitStart", but it's actually align imag left and top of it's parent.

So any idea how I can align the image correctly as I need?

P.S. I forget to mention that I'm setting the image to my ImageView like this :

    BitmapFactory.Options o2 = new BitmapFactory.Options();
    o2.inTempStorage = new byte[8*1024];

    ops = BitmapFactory.decodeStream(cis,null,o2);
    ImageView view = (ImageView) findViewById(R.id.collection_image_background);
    view.setImageBitmap(ops);
like image 212
Android-Droid Avatar asked Apr 18 '12 12:04

Android-Droid


1 Answers

code seems to be perfect except content area you had assign fill_parent takes whole view and will appear as center, so just modify it by wrap_content

  <ImageView  
            android:id="@+id/collection_image_background"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"  />
like image 64
Mohammed Azharuddin Shaikh Avatar answered Nov 07 '22 06:11

Mohammed Azharuddin Shaikh