通用itemview
来源:互联网 发布:鹰朗el01正品淘宝店 编辑:程序博客网 时间:2024/03/29 17:21
public class SettingItemView extends RelativeLayout { private TextView tv_left; private TextView tv_right; private ImageView iv_left; private ImageView iv_right; private String left; private String right; private int image; private int rightImage; public SettingItemView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.combinationView); left = typedArray.getString(R.styleable.combinationView_left); right = typedArray.getString(R.styleable.combinationView_right); image = typedArray.getResourceId(R.styleable.combinationView_image, -1); rightImage = typedArray.getResourceId(R.styleable.combinationView_rightImage, -1); typedArray.recycle(); LayoutInflater.from(context).inflate(R.layout.setting_item_view1, this); tv_left = (TextView) findViewById(R.id.tv_left); tv_right = (TextView) findViewById(R.id.tv_right); iv_left = (ImageView) findViewById(R.id.iv_left); iv_right = (ImageView) findViewById(R.id.iv_right); if (left != null) { tv_left.setText(left); } if (right != null) { tv_right.setText(right); } iv_left.setImageResource(image); iv_right.setImageResource(rightImage); } public void setRightText(String str){ tv_right.setText(str); } public String getRightText(){ return tv_right.getText().toString(); } public void setTextColor(int textColor) { tv_left.setTextColor(textColor); }}2.attrs.xml<declare-styleable name="combinationView"> <attr name="left" format="string"/> <attr name="right" format="string"/> <attr name="image" format="reference"/> <attr name="rightImage" format="reference"/> <attr name="android:text" /></declare-styleable>
3.xml:setting_item_view1
<?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="44dp" > <ImageView android:id="@+id/iv_left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="10dp" android:src="@drawable/st_rename" /> <ImageView android:id="@+id/iv_right" android:layout_width="10dp" android:layout_height="15dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_margin="10dp"/> <TextView android:id="@+id/tv_left" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@+id/iv_left" android:layout_toRightOf="@+id/iv_left" android:textSize="18dp" android:textColor="@android:color/black" /> <TextView android:id="@+id/tv_right" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@+id/tv_left" android:layout_toLeftOf="@+id/iv_right" android:textSize="18dp" android:textColor="@color/st_grey"/></RelativeLayout>
4.引用<com.views.setting.SettingItemView android:id="@+id/me_mysetting" android:layout_width="wrap_content" android:layout_height="wrap_content" andy:image="@drawable/me_mysetting" andy:left="@string/st_personal_setting"//个人设置文体 andy:rightImage="@drawable/st_more" />
阅读全文
0 0
- 通用itemview
- 点击itemView选中checkbox
- ListView自定义itemView
- 万能的ItemView
- recycleview 的 ItemView常用验证
- ListView 中ItemView 的重用原理
- Android给ListView设置itemView高度
- ExpandListView 多个ItemView的效率优化
- 关于Android ListView 多ItemView的问题
- Android ListView添加多种类型的ItemView
- android中listview中添加多种itemview
- 解析RecyclerView中itemView的动画
- ExpandListView 多个ItemView的效率优化
- RecyclerView的itemView的点击效果
- 一个adapter实现多个itemView
- ClauseView个人中心、设置的ItemView
- ListView、recyclerView的itemView布局注意事项
- 通用
- 网络抓包命令 Tcpdump的详细用法
- css学习笔记-动画
- 浅谈Jquery中的bind(),live(),delegate(),on()绑定事件方式
- 程序猿们_一二三四线城市你更愿意选择去哪里工作?
- spring boot 基础日志配置
- 通用itemview
- 设置linux下heartbeat服务开机启动
- html知识点总结
- B站最新算法2017年有效
- Ajax底层原理及相关小案例
- 机器学习 Machine Learning 学习资料
- java容器之九_ConcurrentHashMap
- struts2中如何控制iterator中显示几条数据
- CEF3开发者系列之CEF3入门