自定义View六
来源:互联网 发布:藤井莉娜开的淘宝店铺 编辑:程序博客网 时间:2024/04/29 05:22
组合控件 TitleView extends FrameLayout
组合控件的意思就是,我们并不需要自己去绘制视图上显示的内容,而只是用系统原生的控件就好了
顾明思异,就是将各种控件组合起来呗
思路:
不用多想,先初始化各种需要的东西
先贴出要在TitleView里面加入的布局吧
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:gravity="center_vertical" android:layout_height="50dp" android:background="#ffcb05"> <Button android:id="@+id/button_left" android:layout_marginLeft="5dp" android:layout_width="70dp" android:background="@null" android:layout_height="40dp" android:text="Back" /> <TextView android:id="@+id/text_title" android:gravity="center" android:text="标题" android:textColor="#f00" android:textSize="20sp" android:layout_centerVertical="true" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /></RelativeLayout>
初始化
private void init(){ View view = View.inflate(getContext(), R.layout.text_back,this); titleText = (TextView) view.findViewById(R.id.text_title); leftButton = (Button) view.findViewById(R.id.button_left); leftButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((Activity)getContext()).finish(); } }); }
* 实现了点击返回就结束当前Activity,不用再在布局里面添加了,另外,为了让TitleView有更强地扩展性,我们还提供了setTitleText()、setLeftButtonText()、setLeftButtonListener()等方法
public void setTitleText(String text) { titleText.setText(text); } public void setLeftButtonText(String text){ leftButton.setText(text); } public void setLeftButtonListener(OnClickListener l){ leftButton.setOnClickListener(l); }
0 0
- Android 自定义View (六)
- 自定义View六
- Android游戏开发之旅(六)自定义View
- UI(六) 自定义的View作为Layout中的标签
- Android游戏开发之旅六 自定义View
- Android游戏开发之旅(六)自定义View
- Android游戏开发教程之六:自定义View详解
- Android自定义View之六位密码框
- Android--自定义View滑动的六种方法
- 自定义View之仿支付宝输入六位密码
- Android开发-自定义View-AndroidStudio(六)ViewPager再体验
- android 自定义View开发实战(六) 可拖动的GridView
- Android自定义View(六)_Canvas之画布操作
- Android自定义View专题六-PathMeasure实战,仿小红书动态标签
- Android自定义View研究(六)--View中的原点坐标相关问题
- Android自定义View研究(六)--View中的原点坐标相关问题
- 自定义view
- 自定义View
- GDB 资源汇总
- 自定义View五
- [LeetCode] 236. Lowest Common Ancestor of a Binary Tree
- 二进制中1的个数
- Android使用帧动画内存溢出解决方法
- 自定义View六
- Keep on coding 8-26
- 中东网络暗战:针对叙利亚反对派的网络攻击Group5
- SwipeRefreshLayout下拉刷新和上拉加载
- java封神之路
- windows下杀死占用某个端口的进程
- Vmware WorkStation安装Centos7,让虚拟机上外网-----NAT方式
- 学习《Python基础教程(第二版)》笔记2--基础知识
- 求sg值——分析与找规律