Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android image view gravity

How can I dynamically set the gravity ?

Bitmap bmp;
im = new ImageView (this);
bmp=getbmp(img);
im.setImageBitmap(bmp);  

Now I would like to put the image in the top . Ho can I do this without android:gravity in main.xml ?

EDIT :

main.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:scrollbars="vertical"

    >
</ScrollView>

I have a frame layout and I add to it the image , and then the text and I would like the image to be on the top of the screen.

FrameLayout fm = new FrameLayout (this);
fm.addView(im);
fm.addView(fin); // fin = the text view
setContentView(fm);
like image 312
Teo Avatar asked Oct 03 '11 07:10

Teo


People also ask

What is android Layout gravity?

So in general android:layout_gravity attribute is used by child views to tell their parent how they want to be placed inside it, while android:gravity is used by the parent layout to tell the child views how they should be placed inside it.

What is ImageView in android?

Displays image resources, for example Bitmap or Drawable resources. ImageView is also commonly used to apply tints to an image and handle image scaling.

What is gravity start android?

android:gravity is an attribute that sets the gravity of the content of the view its used on. The android:gravity specifies how an object should position its content on both X and Y axis. The possible values of android:gravity are top, bottom, left, right, center, center_vertical, center_horizontal etc.

What is gravity and Layout gravity?

The android:gravity attribute is used to arrange the position of the content inside a view (for example text inside a Button widget). The android:layout_gravity is used to arrange the position of the entire View relative to it's container.


1 Answers

Use ImageView.setScaleType() with ImageView.ScaleType.FIT_START as value.

like image 112
Mahdi Hijazi Avatar answered Sep 23 '22 15:09

Mahdi Hijazi