模仿 ios 分段单选
http://blog.csdn.net/qduningning/article/details/37935227
res/drawable/seg_left.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_selected="true">
<shape >
<stroke android:color="#0079FF" android:width="1dp"/>
<solid android:color="#0079FF"/>
<corners android:topLeftRadius="3dp" android:bottomLeftRadius="3dp" android:topRightRadius="0dp" android:bottomRightRadius="0dp"/>
</shape>
</item>
<item>
<shape >
<stroke android:color="#0079FF" android:width="1dp"/>
<solid android:color="#FFFFFF"/>
<corners android:topLeftRadius="3dp" android:bottomLeftRadius="3dp" android:topRightRadius="0dp" android:bottomRightRadius="0dp"/>
</shape>
</item>
</selector>
res/drawable/seg_right.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_selected="true">
<shape >
<stroke android:color="#0079FF" android:width="1dp"/>
<solid android:color="#0079FF"/>
<corners android:topLeftRadius="0dp" android:bottomLeftRadius="0dp" android:topRightRadius="3dp" android:bottomRightRadius="3dp"/>
</shape>
</item>
<item>
<shape >
<stroke android:color="#0079FF" android:width="1dp"/>
<solid android:color="#FFFFFF"/>
<corners android:topLeftRadius="0dp" android:bottomLeftRadius="0dp" android:topRightRadius="3dp" android:bottomRightRadius="3dp"/>
</shape>
</item>
</selector>
字体颜色: res/drawable/seg_text_color_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_selected="true" android:color="#FFFFFF"/>
<item android:color="#0079FF"/>
</selector>
package cn.haiwan.app.widget;
import org.xmlpull.v1.XmlPullParser;
import android.R.integer;
import android.content.Context;
import android.content.res.ColorStateList;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.haiwan.R;
public class SegmentView extends LinearLayout {
private TextView textView1;
private TextView textView2;
private onSegmentViewClickListener listener;
public SegmentView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public SegmentView(Context context) {
super(context);
init();
}
private void init() {
// this.setLayoutParams(new LinearLayout.LayoutParams(dp2Px(getContext(), 60), LinearLayout.LayoutParams.WRAP_CONTENT));
textView1 = new TextView(getContext());
textView2 = new TextView(getContext());
textView1.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
textView2.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1));
textView1.setText("SEG1");
textView2.setText("SEG2");
XmlPullParser xrp = getResources().getXml(R.drawable.seg_text_color_selector);
try {
ColorStateList csl = ColorStateList.createFromXml(getResources(), xrp);
textView1.setTextColor(csl);
textView2.setTextColor(csl);
} catch (Exception e) {
}
textView1.setGravity(Gravity.CENTER);
textView2.setGravity(Gravity.CENTER);
textView1.setPadding(3, 6, 3, 6);
textView2.setPadding(3, 6, 3, 6);
setSegmentTextSize(16);
textView1.setBackgroundResource(R.drawable.seg_left);
textView2.setBackgroundResource(R.drawable.seg_right);
textView1.setSelected(true);
this.removeAllViews();
this.addView(textView1);
this.addView(textView2);
this.invalidate();
textView1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (textView1.isSelected()) {
return;
}
textView1.setSelected(true);
textView2.setSelected(false);
if (listener != null) {
listener.onSegmentViewClick(textView1, 0);
}
}
});
textView2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (textView2.isSelected()) {
return;
}
textView2.setSelected(true);
textView1.setSelected(false);
if (listener != null) {
listener.onSegmentViewClick(textView2, 1);
}
}
});
}
public void setSegmentTextSize(int dp) {
textView1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, dp);
textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, dp);
}
private static int dp2Px(Context context, float dp) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
public void setOnSegmentViewClickListener(onSegmentViewClickListener listener) {
this.listener = listener;
}
public void setSegmentText(CharSequence text,int position) {
if (position == 0) {
textView1.setText(text);
}
if (position == 1) {
textView2.setText(text);
}
}
public static interface onSegmentViewClickListener{
public void onSegmentViewClick(View v,int position);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <cn.haiwan.app.widget.SegmentView
android:layout_width="160dp"
android:layout_height="wrap_content"android:layout_centerHorizontal="true"
/>
</LinearLayout>
模仿 ios 分段单选的更多相关文章
- js模仿ios select效果
github:https://github.com/zhoushengmufc/iosselect webapp模仿ios下拉菜单 html下拉菜单select在安卓和IOS下表现不一样,iossel ...
- Android模仿iOS iMessages10照片选择器的实现
不知不觉已经接近半年多没有写过博客了,这段时间,也是我刚好毕业走出校园的时间,由于学习工作的原因,一直没有真正静下心来写下些什么东西.这个星期刚入了小米笔记本pro的坑,本着新电脑新生活的理念嘻嘻-- ...
- iOS分段选择器、旅行App、标度尺、对对碰小游戏、自定义相册等源码
iOS精选源码 企业级开源项目,模仿艺龙旅行App 标签选择器--LeeTagView CSSegmentedControl常用的分段选择器,简单易用! 仿微信左滑删除 IOS左滑返回 输入框 iOS ...
- ul、li模仿ios的TableView实现城市选择
最近项目一个接着一个,之前说的精创环的项目还没做完,今天说先把那个放一下,先做访客系统,销售会见客户之后可以对客户进行一个跟踪记录,原型图也给了,今日头条的频道自定义页面一样. 如果是在IOS上让我来 ...
- 最新模仿ios版微信应用源码
这个是刚刚从那个IOS教程网http://ios.662p.com分享来的,也是一个很不错的应用源码,仿微信基本功能.基于XMPP服务器的即时通信以及交友客户端. ----第一期代码的功能如下---- ...
- iOS/swift 单选框和复选框
/** 复选框 */ import UIKit class LYBmutipleSelectView: UIView { var selectindexs:[Int]=[]//选中的 //标题数组 v ...
- 模仿ios下的coverflow
Android高级图片滚动控件,编写3D版的图片轮播器 http://blog.csdn.net/guolin_blog/article/details/17482089 A cool Open So ...
- iOS - UITableView 单选功能实现
#import <UIKit/UIKit.h> @interface TestCell : UITableViewCell @property(nonatomic,copy)NSStrin ...
- iOS:iOS开发非常全的三方库、插件等等
iOS开发非常全的三方库.插件等等 github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自git ...
随机推荐
- 设置EXCEL2010打开多个独立窗口
最近发现一个奇怪的问题,发现office中的word和ppt在我使用笔记本分屏幕(双屏)的时候都可以将2份文档分别在2个窗口打开,但是在使用excel的时候却发现不行,最后研究发现原因 ...
- u检验、t检验、F检验、X2检验 (转)
http://blog.renren.com/share/223170925/14708690013 常用显著性检验 1.t检验 适用于计量资料.正态分布.方差具有齐性的两组间小样本比较.包括配对资料 ...
- ie F12开发工具出不来
IE的F12开发人员工具不显示问题: 按下F12之后,开发人员工具在桌面上看不到,但是任务栏里有显示.将鼠标放在任务栏的开发人员工具上,出现一片透明的区域,选中之后却出不来.将鼠标移动到开发人员工具的 ...
- 无法挂载 “7.9 GB Filesystem”.
有个8G的U盘,格式化成exfat格式.插入电脑后点击盘符,弹出错误提示: 无法挂载 “7.9 GB Filesystem”. Error mounting: mount exited with ex ...
- delphi xe5 android tts(Text To Speech)
TTS是Text To Speech的缩写,即“从文本到语音”,是人机对话的一部分,让机器能够说话. 以下代码实现xe5 开发的文本转语音的方法 和访问蓝牙一样,这里用javaclass的接口实现 接 ...
- ORACLE临时表 转 学习用
转:http://www.2cto.com/database/201210/163979.html 临时表:像普通表一样,有结构,但是对数据的管理上不一样,临时表存储事务或会话的中间结果集,临时表中保 ...
- [改善Java代码]边界,边界,还是边界
建议24:边界,边界,还是边界 import java.util.Scanner; public class Client { //一个会员拥有产品的最大数量 public final static ...
- asp.net的CascadingDropDown取值和赋值
获取选择的值 可以使用形如以下的方式获得选择的值: Label1.Text = ddlProvince.SelectedValue; Label2.Text=ddlCity.Select ...
- .net平台 .net Framework 组织结构 .net Framework类库 CLR C# 介绍
一..net平台 .NET现在可以看成微软的一个品牌,微软有两个非常成功的品牌,那就是Windows和Office. .NET会成为微软的另一个品牌.它不仅仅是一组技术,产品,或服务(微软的服务包括M ...
- ubuntu共享文件夹给virtualbox
在ubuntu或者linuxmint等linux系统下安装了virtualbox,可以通过共享文件夹的方式,把文件夹共享给virtualbox下的虚拟机系统,我这里的虚拟机系统是win7,共享过程如下 ...