- 浏览: 1094755 次
- 性别:
- 来自: 郑州
文章分类
最新评论
-
baiyi168:
非常有用,多谢楼主
Android中的一个TextView中的字体设置不同大小 -
qq271629261:
[img] ...
android开发工具 Eclipse+Android SDK+ADT -
txlong_onz:
haotainan 写道Activity伪造Dialog,这个 ...
Activity伪造Dialog的时候不能全屏显示 -
haotainan:
Activity伪造Dialog,这个Dialog显示的时候界 ...
Activity伪造Dialog的时候不能全屏显示 -
gangbener:
cainingyouyou 写道7楼的,tag,怎么解决的啊1 ...
android中ListView点击和里边按钮或ImageView点击不能同时生效问题解决
1、首先设计main.xml文件
<?xml version="1.0" encoding="utf-8"?> <ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myFilpper" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/red"> <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:textColor="@drawable/black" android:textSize="30dip"/> <Spinner android:id="@+id/sp1" android:entries="@array/citys" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <ImageView android:id="@+id/im1" android:src="@drawable/icon" android:layout_gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/green"> <TextView android:id="@+id/tv2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:textColor="@drawable/black" android:textSize="30dip"/> <Spinner android:id="@+id/sp2" android:entries="@array/citys" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <ImageView android:id="@+id/im2" android:src="@drawable/icon" android:layout_gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@color/blue"> <TextView android:id="@+id/tv3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:textColor="@drawable/black" android:textSize="30dip"/> <Spinner android:id="@+id/sp3" android:entries="@array/citys" android:layout_gravity="center_horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <ImageView android:id="@+id/im3" android:src="@drawable/icon" android:layout_gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> </ViewFlipper>
2、编写界面切换是的效果(xml)
2.1、push_left_in.xml和push_left_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="500" /> <alpha android:fromAlpha="0.1" android:toAlpha="1.0" android:duration="500" /> </set> <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="-100%p" android:duration="500" /> <alpha android:fromAlpha="1.0" android:toAlpha="0.1" android:duration="500" /> </set>
2.2、push_right_in.xml和push_right_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="-100%p" android:toXDelta="0" android:duration="500" /> <alpha android:fromAlpha="0.1" android:toAlpha="1.0" android:duration="500" /> </set> <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="100%p" android:duration="500" /> <alpha android:fromAlpha="1.0" android:toAlpha="0.1" android:duration="500" /> </set>
3、编写activity实现OnGestureListener接口
package com.jftt; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.MotionEvent; import android.view.View; import android.view.animation.AnimationUtils; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.Spinner; import android.widget.TextView; import android.widget.ViewFlipper; import com.jftt.pojo.City; import com.jftt.pojo.City_Web; import com.jftt.pojo.WebSite; import com.jftt.service.DBManager; public class FlipperDemo extends Activity implements OnGestureListener { private ViewFlipper flipper; private GestureDetector detector; private TextView tv1, tv2, tv3; private Spinner sp1, sp2, sp3; private ImageView im1, im2, im3; private ArrayAdapter<String> adapter; private List<String> citys1, citys2, citys3; private DBManager dbManager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); dbManager = new DBManager(this); addData(); tv1 = (TextView) findViewById(R.id.tv1); tv2 = (TextView) findViewById(R.id.tv2); tv3 = (TextView) findViewById(R.id.tv3); sp1 = (Spinner) findViewById(R.id.sp1); sp2 = (Spinner) findViewById(R.id.sp2); sp3 = (Spinner) findViewById(R.id.sp3); im1 = (ImageView) findViewById(R.id.im1); im2 = (ImageView) findViewById(R.id.im2); im3 = (ImageView) findViewById(R.id.im3); detector = new GestureDetector(this); flipper = (ViewFlipper) findViewById(R.id.myFilpper); tv1.setText("拉手"); tv2.setText("淘宝"); tv3.setText("阿里巴巴"); citys1 = dbManager.findCitiesByIDs(dbManager.findCityIdByWebID(1)); Log.e("myTag", dbManager.findCityIdByWebID(1).toString()); Log.e("myTag", dbManager.findCitiesByIDs(dbManager.findCityIdByWebID(1)).toString()); adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, citys1); // 设置下拉样式 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // 为下拉列表设置适配器 sp1.setAdapter(adapter); // 定义子元素选择监听器 // 为下拉列表绑定事件监听器 sp1.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { im1.setImageResource(getIcon(dbManager .findCityPicByCityName(sp1.getSelectedItem().toString()))); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); citys2 = dbManager.findCitiesByIDs(dbManager.findCityIdByWebID(2)); adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, citys2); // 设置下拉样式 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // 为下拉列表设置适配器 sp2.setAdapter(adapter); // 定义子元素选择监听器 // 为下拉列表绑定事件监听器 sp2.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { im2.setImageResource(getIcon(dbManager .findCityPicByCityName(sp2.getSelectedItem().toString()))); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); citys3 = dbManager.findCitiesByIDs(dbManager.findCityIdByWebID(3)); adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, citys3); // 设置下拉样式 adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // 为下拉列表设置适配器 sp3.setAdapter(adapter); // 定义子元素选择监听器 // 为下拉列表绑定事件监听器 sp3.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { im3.setImageResource(getIcon(dbManager .findCityPicByCityName(sp3.getSelectedItem().toString()))); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); } private int getIcon(String cityName) { if (cityName.equals("suzhou")) { return R.drawable.suzhou; } if (cityName.equals("beijing")) { return R.drawable.beijing; } if (cityName.equals("zhengzhou")) { return R.drawable.zhengzhou; } if (cityName.equals("guangzhou")) { return R.drawable.guangzhou; } if (cityName.equals("shenzhen")) { return R.drawable.shenzhen; } if (cityName.equals("chengdu")) { return R.drawable.chengdu; } if (cityName.equals("dalian")) { return R.drawable.dalian; } if (cityName.equals("shanghai")) { return R.drawable.shanghai; } if (cityName.equals("wuhan")) { return R.drawable.wuhan; } return 0; } private void addData() { if (dbManager.getCwCount() == 0) {City_Web[] cityWebs = new City_Web[] { new City_Web(1, 1), new City_Web(3, 1), new City_Web(5, 1), new City_Web(7, 1), new City_Web(2, 2), new City_Web(4, 2), new City_Web(6, 2), new City_Web(8, 2), new City_Web(1, 3), new City_Web(3, 3), new City_Web(5, 3), new City_Web(7, 3), new City_Web(9, 3) }; dbManager.insertCws(cityWebs); } if (dbManager.getCityCount() == 0) {City[] cities = new City[] { new City("苏州", "suzhou"), new City("北京", "beijing"), new City("郑州", "zhengzhou"), new City("广州", "guangzhou"), new City("深圳", "shenzhen"), new City("成都", "chengdu"), new City("大连", "dalian"), new City("上海", "shanghai"), new City("武汉", "wuhan"), }; dbManager.insertCities(cities); } if (dbManager.getWebCount() == 0) {WebSite[] webSites = new WebSite[] { new WebSite("拉手", "http://www.lashou.com"), new WebSite("淘宝", "http://www.taobao.com"), new WebSite("阿里巴巴", "http://www.alibaba.com") }; dbManager.insertWebSite(webSites); } } @Override public boolean onTouchEvent(MotionEvent event) { return detector.onTouchEvent(event); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (e1.getX() - e2.getX() > 120) { this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_in)); this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_left_out)); this.flipper.showNext(); return true; } else if (e1.getX() - e2.getX() < -120) { this.flipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_in)); this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_right_out)); this.flipper.showPrevious(); return true; } return false; } @Override public boolean onDown(MotionEvent e) { return false; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onSingleTapUp(MotionEvent e) { return false; } }
发表评论
-
安卓自动编译工具Gradle
2015-09-02 15:15 1060https://developer.android.com ... -
图片的水平平铺效果
2014-03-10 15:45 2392Android要实现图片的水平平铺效果: 很简单也很强大, ... -
LinearLayout中的属性baselineAligned的使用
2013-10-19 18:54 34362Android线性布局中的属性主要的就是控制浮动方向的or ... -
Activity伪造Dialog的时候不能全屏显示
2013-05-31 08:42 14186使用Activity伪造Dialog的时候出现不能全屏的问 ... -
修改局部源码烧录手顺
2012-08-16 09:23 20811. 添加命令到PATH路径下,方便全局使用: andro ... -
备份我的源码烧录的sh文件
2012-07-16 10:39 1326烧录编译的img文件: 01.tofastboot.sh ... -
备份我的源码编译的sh文件
2012-07-16 10:34 1538编译命令写一次就可以了。以后直接使用。 01-extra_s ... -
ADT20安装报错
2012-06-29 23:44 9130Cannot complete the install bec ... -
ubuntu12.04(VirtualBox) 64-bit build android source
2012-05-20 17:33 29731.download VirtalBox(Virtual ... -
搭建android源码编译开发服务器
2012-05-20 17:32 72761.android服务器,其实也就是台式机器的增强版本。基本上 ... -
ADT离线安装报错
2012-04-23 09:37 3335最近使用ADT的离线zip包安装ADT总是报错。说是 Can ... -
Android源码编译中的Makefile文件
2012-04-18 09:09 24341.和大多shell文件一样,makefile中的#表示注释, ... -
遍历android根目录的简单资源查看器
2012-04-16 17:02 3684效果如图: package com.txl.sua; ... -
Nexus s与android4.0
2011-12-14 13:15 13681.内核源码链接 http://android.git.ke ... -
Android编译生成系统-译文
2011-12-08 11:21 3435生成 4.0.1 系统 下边 ... -
Android中设置TextView的颜色setTextColor
2011-11-10 11:34 182257android中设置TextView的颜色有方法setTex ... -
Android中设置activity的background为Wallpaper
2011-08-15 08:34 3838<activity android:name=&q ... -
android程序中怎么实现平铺效果
2011-08-10 17:06 4887很简单,就像window桌面图片一样,如果图片小的话就会平铺。 ... -
一个android应用向Home screen添加多个Widget
2011-08-09 15:12 5137如Twitter客户端或者HTC的日历应用,可以添加大小不 ... -
怎么实现Widget中的动画效果,如渐入等
2011-08-09 11:22 3014怎么在Widget中添加animation,如渐入渐出,淡入淡 ...
相关推荐
NULL 博文链接:https://txlong-onz.iteye.com/blog/811257
android sqlite操作 demo
基于Android的SQLite数据库操作Demo
写了个小demo对Sqlite数据的操作,欢迎下载!
这是一个简单的sqlite数据库操作,包含增删改查
关于Android SQLite的基本操作,留作以后使用
Android操作SQLite数据库Demo,实现对数据库的创建,升级,增删查改,用子线程做,避免主线程阻塞。(用Android Studio打开)
这个是android 本地sqlite升级的demo源代码,相关文章请访问:http://blog.csdn.net/bright789
SQLite数据库操作demo
SQlite开发的完整demo,功能有: 1,建了一个表,结构是id+姓名 2,可以删除 增加 更新记录 3,解决了Android的SQlite先天不足:删除 插入后主键不能自动排序的问题 4,在数据库主界面,有“选定”按钮,点此后切换...
android存取Sqlite3数据库demo,已经运行ok,可以用adb登陆查看结果,可供快速掌握sqlite3
android sqlite数据库 demo code 小型便签 实现增加和编辑。删除数据 结构化存储数据
Android Sqlite数据库demo
Android Sqlite使用demo
帮朋友写的SQLite操作demo,比较简单,注释很详细,主要是一些入门级的操作
JavaScript操作SQLite数据库Demo,不需要安装软件,可直接操作SQLite数据库。(推荐下载SQLiteStudio查看生成的数据是否正确)。
Android SQLite ListView Demo 1.SQLite数据库的使用 2.ListView显示数据库数据 3.SQLite操作