2023年7月16日发(作者:)
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/logo"
android:src="@drawable/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
这样一个ImageView控件就乖乖的待在你选定区域的正中间了。 gravity的属性值还有很多,可以单独设置水平或垂直居中。大家可以查看相应的文档,或使用Eclipse的提示功能快速查看。
来源:清源教育
发布者:admin,转转请注明出处:http://www.yc00.com/news/1689448636a249896.html
评论列表(0条)