自定义标题栏遇到的问题
来源:互联网 发布:网络架空地板价格 编辑:程序博客网 时间:2024/05/20 11:25
今天快被自己蠢哭了,研究了一个晚上,在搞标题栏右边的options按钮。
最开始用< Button > 标签,可是不管怎么调整,要么图片会自动加上一个背景,要么图片不在button视图的正中间显示,如下所示:
用background属性,图片被拉伸
使用src属性,图片被添加上了背景,这时候如果同时使用background属性,那么图片就显示不出来,和layout同色了
`
drawableXXX,src,background属性都研究了一下,,,最后也算小有收获,最起码学习了drawableStart和drawableEnd等属性,这个的效果如下图:
就是左边按钮显示出来的效果,就是图片按钮旁边可以写文字,和QQ一样的效果哈。然后就是右边的options按钮啦,哈哈,改用了< ImageButton >就好啦,然后直接指定src为所需图片就能很好的显示啦,不过后来又遇到一点小问题,就是这样:
解决方式就是加上这段代码:
android:layout_alignBottom="@id/button_back"
官方说明:android:layout_alignBottom____Makes the bottom edge of this view match the bottom edge of the given anchor view ID. Accommodates bottom margin.Must be a reference to another resource, in the form “@[+][package:]type:name” or to a theme attribute in the form “?[package:][type:]name”.This corresponds to the global attribute resource symbol layout_alignBottom.
贴上xml完整代码:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/title_layout" android:background="#4b7df1"> <Button android:id="@+id/button_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#4b7df1" android:drawableStart="@drawable/back" android:text="@string/back" android:textColor="#f1f1f1"/> <TextView android:layout_toRightOf="@id/button_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/title_text"/> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#4b7df1" android:src="@drawable/option" android:layout_marginEnd="8dp" android:layout_alignParentEnd="true" android:layout_alignBottom="@id/button_back"/></RelativeLayout>
最后效果:
- 自定义标题栏遇到的问题
- 自定义标题栏的问题
- Android中取消标题栏遇到的问题
- 解决android自定义标题栏充满的问题
- 解决android自定义标题栏充满的问题
- 解决android自定义标题栏充满的问题
- 解决android自定义标题栏充满的问题
- 解决android自定义标题栏充满的问题
- 解决android自定义标题栏充满的问题
- 解决android自定义标题栏充满的问题
- 解决android自定义标题栏充满的问题
- 解决android自定义标题栏充满的问题
- 解决android自定义标题栏充满的问题
- 解决android自定义标题栏充满的问题
- 自定义MKAnnotation遇到的问题
- 自定义相机遇到的问题
- 自定义view遇到的问题
- 自定义的顶部标题栏
- LeetCode143—Reorder List
- STM32F0非对齐访问引起的硬件错误及其排除
- lightoj 1019 模板dijkstra
- (java)链表的转换
- 典型飞行控制系统的回路构成
- 自定义标题栏遇到的问题
- OSS是什么玩意?
- React(6)--组件的复合
- LeetCode 371. Sum of Two Integers 题解(C++)
- 大数的四则运算
- Java的基本程序设计3
- 骑马修栅栏(欧拉路)
- Sublime text3使用Emmet
- 安装windows 版caffe 的一点经验