安卓:中心图像图像、中心

2023-09-03 21:20:22 作者:在类型上可分类伤感的

我有一个线性布局和图像...

I've got a linear layout and an image...

<?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>

如何动态地中心我的形象,这样它会出现在屏幕上的所有设备的中心?

How do I dynamically center my image so that it will appear in the center of the screen on all devices?

推荐答案

的LinearLayout ,使用安卓layout_gravity =中心

RelativeLayout的,使用机器人:layout_centerInParent =真正的