www.tsingyuan
android在Layout中设置控件水平或垂直居中
要想让您的控件水平居中或垂直居中其实很简单,只要在控件的上一级中设置【android:gravity="center"】属性即可
如:
android:orientation="vertical"
android:gravity="center"
android:background="#000000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
android:id="@+id/l ogo"
android:src="@drawabl e/l ogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android layout布局这样一个ImageView控件就乖乖的待在你选定区域的正中间了。gravity的属性值还有很多,可以单独设置水平或垂直居中。大家可以查看相应的文档,或使用Eclipse的提示功能快速查看。
来源:清源教育