- 浏览: 5833860 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (890)
- WindowsPhone (0)
- android (88)
- android快速迭代 (17)
- android基础 (34)
- android进阶 (172)
- android高级 (0)
- android拾遗 (85)
- android动画&效果 (68)
- Material Design (13)
- LUA (5)
- j2me (32)
- jQuery (39)
- spring (26)
- hibernate (20)
- struts (26)
- tomcat (9)
- javascript+css+html (62)
- jsp+servlet+javabean (14)
- java (37)
- velocity+FCKeditor (13)
- linux+批处理 (9)
- mysql (19)
- MyEclipse (9)
- ajax (7)
- wap (8)
- j2ee+apache (24)
- 其他 (13)
- phonegap (35)
最新评论
-
Memories_NC:
本地lua脚本终于执行成功了,虽然不是通过redis
java中调用lua脚本语言1 -
ZHOU452840622:
大神://处理返回的接收状态 这个好像没有监听到 遇 ...
android 发送短信的两种方式 -
PXY:
拦截部分地址,怎么写的for(int i=0;i<lis ...
判断是否登录的拦截器SessionFilter -
maotou1988:
Android控件之带清空按钮(功能)的AutoComplet ...
自定义AutoCompleteTextView -
yangmaolinpl:
希望有表例子更好。。。,不过也看明白了。
浅谈onInterceptTouchEvent、onTouchEvent与onTouch
这个是不带动画效果,要动画效果的看后面的文章。
public class TabSwitcher extends LinearLayout{ private static final String tag="TabSwitcher"; private Context context; private String[] texts; private int arrayId; private int selectedPosition=0; private int oldPosition=selectedPosition; private int[] background={R.drawable.tabswitcher_short,Color.TRANSPARENT}; private TextView[] tvs; public TabSwitcher(Context context) { super(context); // TODO Auto-generated constructor stub init(); } public TabSwitcher(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub Log.i(tag, "--------------TabSwitcher2---------------------"); init(); TypedArray a=context.obtainStyledAttributes(attrs,R.styleable.custom); arrayId=a.getResourceId(R.styleable.custom_arrayId, 0); selectedPosition=a.getInt(R.styleable.custom_selectedPosition, 0); a.recycle(); } private void init(){ context=getContext(); setOrientation(HORIZONTAL); LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); setLayoutParams(params); // texts=new String[]{"游戏","应用","娱乐"}; setBackgroundResource(R.drawable.tabswitcher_long); } @Override protected void onFinishInflate() { // TODO Auto-generated method stub super.onFinishInflate(); Log.i(tag, "--------------onFinishInflate---------------------"); if(arrayId!=0){ texts=getResources().getStringArray(arrayId); }else{ texts=new String[]{}; } tvs=new TextView[texts.length]; LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT); params.weight=1; params.gravity=Gravity.CENTER_VERTICAL; for(int i=0;i<texts.length;i++){ TextView child=new TextView(context); child.setTag(i); // child.setText(texts[i]); child.setTextSize(16); child.setTextColor(Color.BLACK); child.setGravity(Gravity.CENTER); tvs[i]=child; child.setOnClickListener(listener); this.addView(child, params); } } OnClickListener listener = new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub selectedPosition=(Integer)v.getTag(); if(selectedPosition!=oldPosition){ tvs[oldPosition].setBackgroundColor(background[1]); oldPosition=selectedPosition; ((TextView)v).setBackgroundResource(background[0]); if(onItemClickLisener!=null){ onItemClickLisener.onItemClickLisener(v, selectedPosition); } } } }; @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { // TODO Auto-generated method stub super.onSizeChanged(w, h, oldw, oldh); Log.i("tag", "---------------onSizeChanged--------------------"); if(selectedPosition>texts.length-1){ throw new IllegalArgumentException("The selectedPosition can't be > texts.length."); } oldPosition=selectedPosition; for(int i=0;i<texts.length;i++){ tvs[i].setText(texts[i]); if(selectedPosition==i){ tvs[i].setBackgroundResource(background[0]); }else{ tvs[i].setBackgroundColor(background[1]); } } } private OnItemClickLisener onItemClickLisener; public void setOnItemClickLisener(OnItemClickLisener onItemClickLisener) { this.onItemClickLisener = onItemClickLisener; } public interface OnItemClickLisener{ void onItemClickLisener(View view,int position); } public void setTexts(String[] texts) { this.texts = texts; } public void setSelectedPosition(int selectedPosition) { this.selectedPosition = selectedPosition; } }
用法:
import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.View; import android.widget.Toast; import com.yiyou.ui.view.TabSwitcher; import com.yiyou.ui.view.TabSwitcher.OnItemClickLisener; public class MainActivity extends Activity{ private Context context; private TabSwitcher tabSwitcher; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); context=this; tabSwitcher=(TabSwitcher)findViewById(R.id.tabSwitcher); tabSwitcher.setOnItemClickLisener(onItemClickLisener); // tabSwitcher.setTexts(new String[]{"1","2","3"}); //tabSwitcher.setSelectedPosition(1); } OnItemClickLisener onItemClickLisener=new OnItemClickLisener(){ @Override public void onItemClickLisener(View view, int position) { // TODO Auto-generated method stub // switch (position) { case 0: case 1: case 2: Toast.makeText(context, "position clicked:"+position, Toast.LENGTH_SHORT).show(); break; default: break; } } }; }
attrs.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="custom"> <attr name="arrayId" format="reference" /> <attr name="selectedPosition" format="integer" /> </declare-styleable> </resources>
小屏幕的使用下面这张图片代替工程中的图片,否则图片会切掉!
Android Toggle Switch, a customizable extension of Android Switches
https://github.com/BelkaLab/Android-Toggle-Switch
发表评论
-
NestedScrollView滚动到顶部固定子View悬停挂靠粘在顶端
2018-10-31 20:45 7037网上有一个StickyScrollView,称之为粘性Scro ... -
自定义Behavior实现AppBarLayout越界弹性效果
2017-03-31 09:33 10396一、继承AppBarLayout.Beha ... -
Android - 一种相似图片搜索算法的实现
2017-03-31 09:33 2636算法 缩小尺寸。 将图片缩小到8x8的尺寸,总共64个 ... -
使用SpringAnimation实现带下拉弹簧动画的 ScrollView
2017-03-30 11:30 2868在刚推出的 Support Library 25.3.0 里面 ... -
Android为应用添加角标(Badge)
2017-03-30 11:21 62101.需求简介 角标是什么意思呢? 看下图即可明了: 可 ... -
Android端与笔记本利用局域网进行FTP通信
2017-03-23 10:17 1000先看图 打开前: 打开后: Activity类 ... -
PorterDuffColorFilter 在项目中的基本使用
2017-03-03 10:58 1370有时候标题栏会浮在内容之上,而内容会有颜色的变化,这时候就要求 ... -
ColorAnimationView 实现了滑动Viewpager 时背景色动态变化的过渡效果
2017-02-24 09:41 2240用法在注释中: import android.anima ... -
迷你轻量级全方向完美滑动处理侧滑控件SlideLayout
2017-01-16 16:53 2610纯手工超级迷你轻量级全方向完美滑动处理侧滑控件(比官方 sup ... -
Effect
2017-01-05 09:57 0https://github.com/JetradarMobi ... -
动态主题库Colorful,容易地改变App的配色方案
2016-12-27 14:49 2584Colorful是一个动态主题库,允许您很容易地改变App的配 ... -
对视图的对角线切割DiagonalView
2016-12-27 14:23 1132提供对视图的对角线切割,具有很好的用户定制 基本用法 ... -
仿淘宝京东拖拽商品详情页上下滚动黏滞效果
2016-12-26 16:53 3523比较常用的效果,有现成的,如此甚好!:) import ... -
让任意view具有滑动效果的SlideUp
2016-12-26 09:26 1721基本的类,只有一个: import android.a ... -
AdvancedWebView
2016-12-21 09:44 16https://github.com/delight-im/A ... -
可设置圆角背景边框的按钮, 通过调节色彩明度自动计算按下(pressed)状态颜色
2016-11-02 22:13 1941可设置圆角背景边框的的按钮, 通过调节色彩明度自动计算按下(p ... -
网络请求库相关
2016-10-09 09:35 62https://github.com/amitshekhari ... -
ASimpleCache一个简单的缓存框架
2015-10-26 22:53 2195ASimpleCache 是一个为android制定的 轻量级 ... -
使用ViewDragHelper实现的DragLayout开门效果
2015-10-23 10:55 3440先看一下图,有个直观的了解,向下拖动handle就“开门了”: ... -
保证图片长宽比的同时拉伸图片ImageView
2015-10-16 15:40 3748按比例放大图片,不拉伸失真 import android. ...
相关推荐
【标题】"TabSwitcher自定义控件(带滑动效果)"揭示了本文将要讨论的是一个特定的Android开发中的自定义用户界面组件。TabSwitcher控件通常用于在多个选项卡之间切换,而且这个控件增加了滑动交互,使得用户体验更加...
本文将深入探讨"TabSwitcher"这一自定义控件,它具备拖动和滑动效果,为用户提供了更流畅、直观的操作体验。通过分析"TabSwitcher"的实现,我们可以学习到如何在Android中创建动态且交互性强的UI组件。 ...
”键)关闭该标签##功能-在打开的标签上应用模糊过滤器-在标签之间快速切换-在过滤过程中关闭所有不相关的标签-不用鼠标; 该扩展程序具有用于激活,切换选项卡,关闭它们的快捷方式等##路线图[x]通过快捷方式激活[x...
TL; DR记住Textmate的Command-T?铬是一样的。 警告:快捷方式必须手动设置在铬的扩展名... TL; DR记住Textmate的Command-T?铬是一样的。 警告:必须在chrome的扩展设置中手动设置快捷方式。...建议:使用alt-space。...
在更复杂的场景中,可以通过`setCompoundDrawablesWithIntrinsicBounds()`方法来设置RadioButton的四周绘制元素,例如,将数字替换为图片,或者自定义一个带有选中状态的Drawable并将其设置为RadioButton的`...
(带有NPM) 安装 git clone 此存储库 切换到新目录 npm install bower install 运行/开发 ember server 访问您的应用程序,为 。 代码生成器 利用许多生成器生成代码,尝试使用ember help generate更多详细信息 ...
在Android开发中,自定义UI元素是提升应用用户体验的重要手段之一。RadioButton作为常用的控件,其默认样式可能无法满足所有设计需求。本文将详细介绍三种方法来定制RadioButton的样式,包括使用XML文件、在Java代码...
`AndroidTabSwither`是一个专为Android平台设计的简单易用的Tab实现库,它允许开发者创建带有可绘制元素和文本元素的选项卡。这个库提供了一种灵活的方式,开发者可以根据自己的需求选择只显示图形或文本,或者两者...
本资源提供了Android系统浏览器的源码以及对应的UML(Unified Modeling Language)分析图,这对于理解浏览器的工作原理、优化性能、自定义功能或开发自己的浏览器应用都有着极大的帮助。 一、Android系统浏览器源码...
语言:English 快速过滤和切换窗口和选项卡 使用选项卡切换器,您可以仅使用键盘快速切换到其他打开的选项卡,包括按部分名称或URL匹配过滤选项卡。...隐私政策请在http://flowapps.co/tabswitcher/privacypoli
快速控制,过滤和切换标签 ...请在https://github.com/kallepersson/tabswitcher中查看源代码。如何更改键盘快捷键以显示Tab切换器? –很简单,您可以在扩展设置页面底部更改键盘快捷键! 支持语言:English
在实际使用中,用户可能需要安装并启用这个扩展,然后在浏览器的某个指定位置(如地址栏旁或自定义快捷键)启动搜索功能。对于经常需要处理大量标签页的用户,例如研究人员、内容创作者或是多任务处理者来说,"提前...