我有线性布局和图像......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:layout_width="wrap_content" android:id="@+id/imageView1"
android:src="@drawable/icon" android:layout_height="wrap_content"
android:scaleType="center"></ImageView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
如何动态居中我的图像,使其显示在所有设备的屏幕中央?
如何动态设置重力?
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)