I am using this code for the image:
我正在使用此代码的图像:
<ImageView android:src="@drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dip"/>
I want the logo to be centered , it can be done by varying the Layout margin left value and check and position it, but is there any command to get it centered?
我希望徽标居中,可以通过改变布局边距左值并检查和定位它来完成,但有没有命令让它居中?
4 个解决方案
#1
1
Try to use RelativeLayout
:
尝试使用RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/app_logo"
android:contentDescription="application_logo"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
If you want to use only horizonal alignment
, only remove android:layout_centerVertical="true"
from XML resource
.
如果您只想使用水平对齐,只从XML资源中删除android:layout_centerVertical =“true”。
#2
0
depending on the other part of your layout you could use a set the gravity of it's parent to center_vertical|center_horizontal.
根据布局的其他部分,您可以使用它的父级重力设置为center_vertical | center_horizontal。
#3
0
You could also use the element android:layout_centerInParent
to center the image in the parent (container)
您还可以使用元素android:layout_centerInParent将图像置于父级(容器)中心
#4
0
even better: use an image file the size of the screen (even fi it has balck space around it)
甚至更好:使用屏幕大小的图像文件(即使它周围有黑色空间)
#1
1
Try to use RelativeLayout
:
尝试使用RelativeLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/app_logo"
android:contentDescription="application_logo"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
If you want to use only horizonal alignment
, only remove android:layout_centerVertical="true"
from XML resource
.
如果您只想使用水平对齐,只从XML资源中删除android:layout_centerVertical =“true”。
#2
0
depending on the other part of your layout you could use a set the gravity of it's parent to center_vertical|center_horizontal.
根据布局的其他部分,您可以使用它的父级重力设置为center_vertical | center_horizontal。
#3
0
You could also use the element android:layout_centerInParent
to center the image in the parent (container)
您还可以使用元素android:layout_centerInParent将图像置于父级(容器)中心
#4
0
even better: use an image file the size of the screen (even fi it has balck space around it)
甚至更好:使用屏幕大小的图像文件(即使它周围有黑色空间)