Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android align top bitmap in imageview

Is there anyway so I can align bitmap in ImageView. I have an issue with my image view. I'm setting it's source via Java Code and after bitmap is resized it's centered in ImageView, but the thing that I want is to align the bitmap.

Declaring the imageView :

    <RelativeLayout
    android:id="@+id/collection_background"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@+id/actionbar" > 


     <ImageView  
        android:id="@+id/collection_image_background"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:contentDescription="@string/stampii"  />

    // countinue ........

and here is how I'm setting the bitmap :

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

Any ides how to do that?

like image 910
Android-Droid Avatar asked Nov 27 '22 09:11

Android-Droid


2 Answers

Add android:scaleType="fitStart" to your ImageView. It is ok for me.

like image 80
rml Avatar answered Dec 16 '22 01:12

rml


You can use android:scaleType to change the alignement in your ImageView.

like image 35
FUBUs Avatar answered Dec 16 '22 00:12

FUBUs