当前位置: 代码迷 >> Android >> android程序在Layout中设置控件水准或垂直居中
  详细解决方案

android程序在Layout中设置控件水准或垂直居中

热度:41   发布时间:2016-05-01 13:58:58.0
android程序在Layout中设置控件水平或垂直居中

??? 要想让您的控件水平居中或垂直居中其实很简单,只要在控件的上一级中设置【android:gravity="center"】属性即可

如:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
??? android:orientation="vertical"
???
android:gravity="center"
??? android:background="#000000"
??? android:layout_width="fill_parent"
??? android:layout_height="fill_parent"
??? >
??? <ImageView
??? android:id="@+id/logo"
??? android:src="@drawable/logo"
??? android:layout_width="wrap_content"
??? android:layout_height="wrap_content"
??? />
</LinearLayout>


??? 这样一个ImageView控件就乖乖的待在你选定区域的正中间了。gravity的属性值还有很多,可以单独设置水平或垂直居中。大家可以查看相应的文档,或使用Eclipse的提示功能快速查看。

?

?

1 楼 yaoneng 2012-05-21  
请问在代码里面怎么写呢
  相关解决方案