Android图像视图重力

Teo*_*Teo 12 android image view gravity

如何动态设置重力?

Bitmap bmp;
im = new ImageView (this);
bmp=getbmp(img);
im.setImageBitmap(bmp);  
Run Code Online (Sandbox Code Playgroud)

现在我想将图像放在顶部.我可以android:gravity在main.xml中执行此操作吗?

编辑:

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>
Run Code Online (Sandbox Code Playgroud)

我有一个框架布局,我添加了图像,然后文本,我希望图像在屏幕的顶部.

FrameLayout fm = new FrameLayout (this);
fm.addView(im);
fm.addView(fin); // fin = the text view
setContentView(fm);
Run Code Online (Sandbox Code Playgroud)

Mah*_*azi 28

将ImageView.setScaleType()与ImageView.ScaleType.FIT_START一起用作值.