`

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的提示功能快速查看。

 

 

0
0
分享到:
评论
1 楼 yaoneng 2012-05-21  
请问在代码里面怎么写呢

相关推荐

Global site tag (gtag.js) - Google Analytics