- 浏览: 1203556 次
- 性别:
- 来自: 荆州
文章分类
- 全部博客 (396)
- Android 基础 (72)
- Java 基础 (42)
- Android(动画效果) (26)
- Android(自定义组件) (13)
- Android(手机服务) (38)
- Android(网络相关) (27)
- Android(多媒体) (12)
- Android(小技巧) (30)
- Android(用户界面) (39)
- 基础概念 (24)
- Android组件学习 (21)
- Android数据库相关 (11)
- 生活杂谈 (10)
- 调试技巧部分 (8)
- Sql Server相关 (1)
- Android(xml相关) (2)
- Android 开发 (12)
- 韩语学习 (4)
- Mac添加环境变量的三种方法 (1)
- iPhone开发 (1)
- Android Studio (1)
最新评论
-
ppfbsar:
下载网络文件到SD卡上 -
851228082:
好文!彻底理解单类型导入与按需导入的区别了。还有一点可以通过 ...
谈java的导入(import) -
麦田的设计者:
老乡啊
sqlite 数据库保存图片 -
sf_dream:
我要是读写list、map之类的集合呢
ObjectOutputStream和ObjectInputStream类的学习 -
xfyunyun:
博主,请问webview加载html字符串时怎么进行缓存处理呢 ...
WebView使用总结2(加载HTML内容形式的String)
先上一张效果图:
以后大家在设计UI时,可以将那些开关型的功能模块使用上述UI原型进行改造:)
DragTab.java文件:
package com.example.ex.view; import com.example.ex.R; import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; public class DragTab extends FrameLayout { private CallDragTab callTab; private int currentTab = -1; private TextView game; private TextView app; private TextView between; private int width; private OnClickListener gameOnClickListener; private OnClickListener appOnClickListener; private boolean right; private int widgetWidth; private int betweenLeft; private int firstX; public DragTab(Context context) { super(context); callTab = (CallDragTab) context; } public DragTab(Context context, AttributeSet attrs) { super(context, attrs); callTab = (CallDragTab) context; } public void setCurrentDrayTab(int curTab) { setCurrentDrayTab(curTab, false); } public void setGameText(int redId) { if (redId > 0) { this.game.setText(redId); } } public void setGameText(String text) { if (text != null && text.length() != 0) { this.game.setText(text); } } public void setAppText(int redId) { if (redId > 0) { this.app.setText(redId); } } public void setAppText(String text) { if (text != null && text.length() != 0) { this.app.setText(text); } } public void setBetweenText(int redId) { if (redId > 0) { this.between.setText(redId); } } public void setBetweenText(String text) { if (text != null && text.length() != 0) { this.between.setText(text); } } @Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getAction(); final int moveX = (int) ev.getX(); final int scape = moveX - firstX; switch (action) { case MotionEvent.ACTION_DOWN: firstX = (int) ev.getX(); break; case MotionEvent.ACTION_MOVE: move(scape); break; case MotionEvent.ACTION_UP: if (currentTab == 1) { if (betweenLeft != 0) { animationStart(-betweenLeft, 0); } callTab.getData(1); } else if (currentTab == 2) { if (betweenLeft != width) { animationStart(betweenLeft, width); } callTab.getData(2); } break; } return true; } private void animationStart(int left, int leftMargin) { TranslateAnimation trans = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0, Animation.ABSOLUTE, left / width, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0); trans.setStartOffset(0); trans.setDuration(100); trans.setFillBefore(false); between.startAnimation(trans); setLayoutParams(leftMargin); } private void move(int scape) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) between .getLayoutParams(); betweenLeft = between.getLeft(); if (width <= scape) { lp.leftMargin = width; } else if (scape <= 0) { if (betweenLeft == width) { right = true; } else if (betweenLeft == 0) { right = false; } if (right) { lp.leftMargin = width + scape; if (lp.leftMargin <= 0) { lp.leftMargin = 0; } } else { lp.leftMargin = scape; if (lp.leftMargin <= 0) { lp.leftMargin = 0; } } } else if (scape > 0 && width > scape) { lp.leftMargin = scape; if (betweenLeft == width) { lp.leftMargin = width; } } if (widgetWidth / 3 <= betweenLeft) { setCurrentDrayTab(2); } else if (widgetWidth / 3 >= betweenLeft) { setCurrentDrayTab(1); } between.setLayoutParams(lp); } public void setCurrentDrayTab(int curTab, boolean isSetLayoutParams) { if (currentTab == curTab) { return; } currentTab = curTab; if (curTab == 1) { game.setVisibility(INVISIBLE); app.setVisibility(VISIBLE); between.setText(game.getText()); if (isSetLayoutParams) { setLayoutParams(0); } } else if (curTab == 2) { app.setVisibility(INVISIBLE); game.setVisibility(VISIBLE); between.setText(app.getText()); if (isSetLayoutParams) { setLayoutParams(width); } } } @Override protected void onFinishInflate() { game = (TextView) findViewById(R.id.game); app = (TextView) findViewById(R.id.app); between = (TextView) findViewById(R.id.between); LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) between .getLayoutParams(); widgetWidth = lp.width; width = (int) (widgetWidth / 1.0); } private void setLayoutParams(int leftMargin) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) between .getLayoutParams(); lp.leftMargin = leftMargin; between.setLayoutParams(lp); } public void setGameClickListener(OnClickListener listener) { if (listener != null) { this.gameOnClickListener = listener; this.game.setOnClickListener(gameOnClickListener); } } public void setAppClickListener(OnClickListener listener) { if (listener != null) { this.appOnClickListener = listener; this.app.setOnClickListener(appOnClickListener); } } public interface CallDragTab { void getData(int curTab); } }
SlideButtonActivity.java:
package com.example.ex; import com.example.ex.view.DragTab; import com.example.ex.view.DragTab.CallDragTab; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Toast; public class SlideButtonActivity extends Activity implements CallDragTab { private DragTab mDragTab; private int currentClick = -1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mDragTab = (DragTab) findViewById(R.id.self_tab); mDragTab.setCurrentDrayTab(1); mDragTab.setGameClickListener(new OnClickListener() { @Override public void onClick(View v) { mDragTab.setCurrentDrayTab(1, true); getData(1); } }); mDragTab.setAppClickListener(new OnClickListener() { @Override public void onClick(View v) { mDragTab.setCurrentDrayTab(2, true); getData(2); } }); getData(1); } @Override public void getData(int curTab) { if (currentClick == curTab) { return; } currentClick = curTab; if (curTab == 1) { Toast.makeText(this, "游戏", Toast.LENGTH_LONG).show(); } else if (curTab == 2) { Toast.makeText(this, "应用", Toast.LENGTH_LONG).show(); } } }
main.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <include layout="@layout/self_tab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/self_tab" /> </LinearLayout>
self_tab.xml:
<?xml version="1.0" encoding="utf-8"?> <com.example.ex.view.DragTab xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="200dp" android:layout_height="wrap_content"> <LinearLayout android:layout_width="200dp" android:layout_height="wrap_content" android:background="@drawable/rank_long"> <TextView android:id="@+id/game" android:layout_width="100dp" android:layout_height="wrap_content" android:text="游戏" android:textSize="16sp" android:textColor="#000000" android:gravity="center_horizontal" android:layout_gravity="center" /> <TextView android:id="@+id/app" android:layout_width="100dp" android:layout_height="wrap_content" android:text="应用" android:textSize="16sp" android:textColor="#000000" android:gravity="center_horizontal" android:layout_gravity="center" /> </LinearLayout> <LinearLayout android:layout_width="200dp" android:layout_height="wrap_content"> <TextView android:id="@+id/between" android:layout_width="100dp" android:layout_height="wrap_content" android:background="@drawable/rank_short" android:text="游戏" android:textSize="16sp" android:textColor="#000000" android:gravity="center" /> </LinearLayout> </com.example.ex.view.DragTab>
本来不想附上源码的,因为代码都贴在这了,还是附上吧,也许有的人需要现成的东东!!!!
评论
8 楼
龙哥IT
2012-06-27
7 楼
yangchch786
2011-12-11
学习了,有个小bug,就是当向左拖动时,scape<0时出现的bug,已经改过
发一下出来。
if(widgetWidth/3 <= lp.leftMargin){
setCurrentDrayTab(2);
}else if(widgetWidth / 3 >= lp.leftMargin){
setCurrentDrayTab(1);
}
这里需要用lp.leftMargin,不用betweenLeft。
if(right){
lp.leftMargin = width + scape;
if(lp.leftMargin<=0){
lp.leftMargin = 0;
}
}else{
lp.leftMargin = 0;
}
这里当right==false时,就把lp.leftMargin设置为0.
发一下出来。
if(widgetWidth/3 <= lp.leftMargin){
setCurrentDrayTab(2);
}else if(widgetWidth / 3 >= lp.leftMargin){
setCurrentDrayTab(1);
}
这里需要用lp.leftMargin,不用betweenLeft。
if(right){
lp.leftMargin = width + scape;
if(lp.leftMargin<=0){
lp.leftMargin = 0;
}
}else{
lp.leftMargin = 0;
}
这里当right==false时,就把lp.leftMargin设置为0.
6 楼
qjx1987904
2011-12-03
很不错,学习了
5 楼
bear1122ccc
2011-10-08
private int width; 这个宽度是代表什么啊?
private int currentTab = -1; 这个又代表哪种状态啊?
private int currentTab = -1; 这个又代表哪种状态啊?
4 楼
bear1122ccc
2011-10-08
求代码注释。
3 楼
huanzi5566
2011-09-05
哇 真厉害
2 楼
lemonboxs
2011-08-19
很好,解决了我的问题。
1 楼
pcq019
2011-08-17
48个浏览,居然没人回复,我来谢谢你啦~
发表评论
-
Android Studio一些使用快捷键
2016-12-17 10:17 67901.command+delete 删除一行代码 2.co ... -
Freeline快速集成
2016-11-11 16:30 78231. Freeline是什么? Freelin ... -
android:installLocation简析
2016-10-08 16:42 6547在Froyo(android 2.2,API Level:8) ... -
防止Service被系统轻易回收
2013-11-09 17:14 7576最近在使用android 4.1系统的时候,发现在手机休眠一段 ... -
手机浏览器打开应用或应用市场
2013-10-17 14:54 2035当在项目中出现下列情形: 应用开发商想对手机注册用 ... -
ListView显示不同布局(模拟ExpandListView)
2013-09-12 15:05 5939public class MainActivity ext ... -
多点触控之MotionEvent.ACTION_MASK作用
2013-07-23 14:49 2020ACTION_MASK在Android中是应用于多点触摸操作, ... -
Using Ant to Automate Building Android Applications
2013-05-23 13:32 2072Using Ant to Automate Building ... -
Android Bitmap getByteCount和getRowBytes
2013-05-03 11:16 2401Bitmap关于内存占用的API 1、getRowB ... -
音频功能实现
2013-04-25 14:49 11371.音频PCM转SPX格式:http://blog.csdn. ... -
MAC下Android的Eclipse开发环境的搭建
2013-04-20 09:42 1101一.Eclipse的下载 ... -
屏幕点亮和关闭广播监听
2013-04-07 21:49 2575private void registerScreenActi ... -
mac上配置adb
2013-04-06 17:50 1285问:为什么要配置ADB ? 答:不配置的话,每次用到ADB都要 ... -
Notification用法复习(3.0以后版本)
2012-11-04 11:33 3121使用Notification的示例代码: public c ... -
Android应用icon图标
2012-07-07 15:02 1528对于Android平台来说,不同分辨率下Icon的大小设计有着 ... -
Android软键盘控制
2012-05-12 17:08 9226整个输入法框架(IMF)结构的核心API,应用程序之间进行调度 ... -
键盘自动弹出
2012-04-25 17:28 1003Timer timer = new Timer(); ... -
Eclipse 默认打开Android xml 布局
2012-04-21 17:02 2047今天新装了Android开发环境后,新建一个工程,打开xml发 ... -
苹果开发android 第一步
2012-04-14 22:50 1146今天开始,准备使用mac来进行android开发,将开发中遇到 ... -
SpannableStringBuilder的简单用法
2012-02-29 14:29 2337一段代码,贴了自己以后看: TextView mText ...
相关推荐
类似Iphone日期选择器功能,该项目实现了类似于Iphone中齿轮状的日期选择器,可以通过点击show picker按钮,会弹出一个对话框,该对话框中的内容即是日期,可以上下滑动进行切换时间,喜欢的朋友可以下载研究一下。
悬浮球插件简单的效果图: 很遗憾,没找到太好的视频转...-- 给定一个初始位置position,插槽中填写想滑动的部分 --> 猪场> 原理示意图 请结合代码注释来理解 悬浮球插件代码如下: <div class=xuan
一个易于使用的 UITableViewCell 子类,它实现了一个可滑动的内容视图,它公开了实用程序按钮(类似于 iOS 7 邮件应用程序) #演示图片 用法 在您的 Podfile 中: pod 'KHSwipeCell', '~> 0.2.0' 或者只是克隆这...
8.3 秘诀:为按钮响应制作动画效果.....196 8.4 秘诀:定制开关.....197 8.5 秘诀:添加自定义滑块缩略图.....200 8.6 秘诀:关闭UITextField 键盘.....204 8.7 秘诀:关闭UITextView 键盘.....205 8.8 秘诀:向文本...
8.3 秘诀:为按钮响应制作动画效果.....196 8.4 秘诀:定制开关.....197 8.5 秘诀:添加自定义滑块缩略图.....200 8.6 秘诀:关闭UITextField 键盘.....204 8.7 秘诀:关闭UITextView 键盘.....205 8.8 秘诀:向文本...
8.3 秘诀:为按钮响应制作动画效果.....196 8.4 秘诀:定制开关.....197 8.5 秘诀:添加自定义滑块缩略图.....200 8.6 秘诀:关闭UITextField 键盘.....204 8.7 秘诀:关闭UITextView 键盘.....205 8.8 秘诀:向文本...
(译)在cocos2d里如何制作各种按钮.pdf (译)如何使用cocos2d制作基于tilemap的游戏教程 第一部分.pdf (译)如何在cocos2d里面使用动画和spritesheet.pdf (译)如何用cocos2d制作iphone游戏:旋转炮塔.pdf (译)如何...
st-slidetoremove-插件滑动删除 Sencha 触摸列表插件SlideToRemove 是 Sencha Touch 2 的一个简单插件,它增加了滑动列表项以在确认后删除它们的功能,非常类似于 iPhone/iPad 上看到的本机 iOS 控件。 有一个支持 ...
在弹出键盘上加上一个按钮,手指按下按钮,并且保持按钮处于按下状态,然后随便在屏幕上滑动手指,便可以任意定位文字光标。 小编注:这一解决方式很类似笔记本电脑键盘上的TrackPoint,用于定位屏幕鼠标。 [优才 ...
10.jquery仿卓越亚马逊网鼠标移到按钮弹出菜单的效果代码 11.jquery浮动变化的个性菜单插件floatmenu下载 12.jQuery黑色风格仿Flash版下滑菜单效果 13.jquery黑色循环滚动菜单特效插件下载 14.jquery灰色...
本文讲述,在使用VUE的移动端实现类似于iPhone的悬浮窗的效果。 相关知识点 touchstart 当在屏幕上按下手指时触发 touchmove 当在屏幕上移动手指时触发 touchend 当在屏幕上抬起手指时触发 mousedown mousemove ...
类似于Path或Facebook应用的效果,允许多个视图左右平移切换。主视图的导航条有两个按钮,点击左边按钮,主视图会往右移动大概4/5,左边4/5的屏幕显示底下的子视图。点击右边按钮,则右边屏幕显示底下另外一个子视图...
(译)在cocos2d里如何制作各种按钮.pdf (译)如何使用cocos2d制作基于tilemap的游戏教程 第一部分.pdf (译)如何在cocos2d里面使用动画和spritesheet.pdf (译)如何用cocos2d制作iphone游戏:旋转炮塔.pdf (译)如何用...
(译)在cocos2d里如何制作各种按钮.pdf (译)如何使用cocos2d制作基于tilemap的游戏教程 第一部分.pdf (译)如何在cocos2d里面使用动画和spritesheet.pdf (译)如何用cocos2d制作iphone游戏:旋转炮塔.pdf (译)如何用...
来源:Licence:Custom平台:iOS设备:iPhone作者:程康_kain 左右菜单例子,类似于...点击主视图的导航条左右两边按钮,就会从左右两边分别滑动出子视图。 Code4App编译测试,适用环境:Xcode 4.3, iOS 5.0。
来电通独家对类似+020110的冒警电话进行了骚扰来电提醒。 如果没被拦截的骚扰来电,骚扰短信,也无需烦恼哦,轻轻一个举报,它便不会再骚扰你啦。 爆点三:全新界面UI,绝对让你眼前一亮。 全新的UI,全新的体验,...