Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android中居中放置UI元素_Android_Imageview_Center - Fatal编程技术网

在Android中居中放置UI元素

在Android中居中放置UI元素,android,imageview,center,Android,Imageview,Center,我正在寻找一种在android中集中UI元素的方法。特别是ImageView。因为我知道我将要显示的图像没有屏幕宽,所以我需要将其居中!有什么办法吗?如果要在布局中居中显示图像视图,请使用布局重力(如果是线性布局) 如果您谈论的是imageView中的图像,请使用imageView的xml中的android:scaleType您可以将imageView定位在相对布局中。使用以下各项设置图像的布局属性: android:layout_centerInParent="true" android:la

我正在寻找一种在android中集中UI元素的方法。特别是ImageView。因为我知道我将要显示的图像没有屏幕宽,所以我需要将其居中!有什么办法吗?

如果要在布局中居中显示图像视图,请使用布局重力(如果是线性布局)
如果您谈论的是imageView中的图像,请使用imageView的xml中的android:scaleType

您可以将imageView定位在相对布局中。使用以下各项设置图像的布局属性:

android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"

只需将其放入一个布局中,如LinearLayout,其宽度类似于“fill\u parent”,对于ImageView本身,请定义android:gravity=“center”,确保ParentRelativeLayout填充要将图像居中的空间。