Android开发:解决android:gravity不能居中问题
2016-04-02 18:43
441 查看
Android开发:解决android:gravity不能居中问题
2011-11-10 09:29:50| 分类: Android|举报|字号 订阅下载LOFTER我的照片书 |
在Android开发中,有时候会发现,使用了 android:gravity 属性,但是相关控件却没有真正的居中。
要使用这个属性,需要满足:本层框架需要是宽度或者高度必须是 "fill_parent"的。
另:理论上讲,android:layout_gravity 属性应该也是类似的。
如:
<LinearLayout
android:layout_width="fill_parent" <!-- 本层布局使用了水平居中,则这里需要设置宽度为"fill_parent" -->
android:layout_height="wrap_content" <!-- 高度方面可以根据实际情况来自定义 -->
android:gravity="center_horizontal" > <!-- 这里使用了水平居中 -->
<Button <!-- 只有满足上面的要求,这个Button才会水平居中 -->
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_big"
android:onClick="onSearch"
android:text="@string/btn_search" />
</LinearLayout>
相关文章推荐
- Android开发中的一个小功能 清空搜索框的文字
- Android开发:setAlpha()方法
- Mac下载安装Android Studio教程
- Android 电子邮件发送成功与失败的提示
- parcelable的使用与seraliezd的使用比较
- Android之获取数据库路径
- Android和“时间”有关的一些常用函数
- mac配置git环境
- Android开发实用技巧之三:定制自己的日志工具LogUtil.java
- 解决android项目65k方法数的限制,让你的应用不在爆棚。
- Android动画二:View动画
- Android postTranslate和preTranslate
- 改进Android SlidingMenu实现QQ样式边侧滑抽屉技术
- 如何将一个 android工程作为依赖工程
- Android学习之Design Support Library中TextInputLayout的使用
- Android studio 布局文件变全黑
- Realm for Android快速入门教程
- Android中的消息通知Toast和Notification
- Android ADT 下载 ( ADT-23.0.7 )
- Android Studio获取数字签名(SHA1)