2B01-View-Switcher
Gallery和swithcer联合使用
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ package com.example.android.apis.view; import com.example.android.apis.R; import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher; public class ImageSwitcher1 extends Activity implements
AdapterView.OnItemSelectedListener, ViewSwitcher.ViewFactory { @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.image_switcher_1); mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this);
mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out)); Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
g.setOnItemSelectedListener(this);
} public void onItemSelected(AdapterView parent, View v, int position, long id) {
mSwitcher.setImageResource(mImageIds[position]);
} public void onNothingSelected(AdapterView parent) {
} public View makeView() {
ImageView i = new ImageView(this);
i.setBackgroundColor(0xFF000000);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
return i;
} private ImageSwitcher mSwitcher; public class ImageAdapter extends BaseAdapter {
public ImageAdapter(Context c) {
mContext = c;
} public int getCount() {
return mThumbIds.length;
} public Object getItem(int position) {
return position;
} public long getItemId(int position) {
return position;
} public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext); i.setImageResource(mThumbIds[position]);
i.setAdjustViewBounds(true);
i.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
i.setBackgroundResource(R.drawable.picture_frame);
return i;
} private Context mContext; } private Integer[] mThumbIds = {
R.drawable.sample_thumb_0, R.drawable.sample_thumb_1,
R.drawable.sample_thumb_2, R.drawable.sample_thumb_3,
R.drawable.sample_thumb_4, R.drawable.sample_thumb_5,
R.drawable.sample_thumb_6, R.drawable.sample_thumb_7}; private Integer[] mImageIds = {
R.drawable.sample_0, R.drawable.sample_1, R.drawable.sample_2,
R.drawable.sample_3, R.drawable.sample_4, R.drawable.sample_5,
R.drawable.sample_6, R.drawable.sample_7}; }
button 和 textSwither配合使用
/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ package com.example.android.apis.view; import com.example.android.apis.R; import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher; /**
* Uses a TextSwitcher.
*/
public class TextSwitcher1 extends Activity implements ViewSwitcher.ViewFactory,
View.OnClickListener { private TextSwitcher mSwitcher; private int mCounter = 0; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.text_switcher_1); mSwitcher = (TextSwitcher) findViewById(R.id.switcher);
mSwitcher.setFactory(this); Animation in = AnimationUtils.loadAnimation(this,
android.R.anim.fade_in);
Animation out = AnimationUtils.loadAnimation(this,
android.R.anim.fade_out);
mSwitcher.setInAnimation(in);
mSwitcher.setOutAnimation(out); Button nextButton = (Button) findViewById(R.id.next);
nextButton.setOnClickListener(this); updateCounter();
} public void onClick(View v) {
mCounter++;
updateCounter();
} private void updateCounter() {
mSwitcher.setText(String.valueOf(mCounter));
} public View makeView() {
TextView t = new TextView(this);
t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
t.setTextSize(36);
return t;
}
}
2B01-View-Switcher的更多相关文章
- 从零开始学ios开发(十):Multiview Applications(多个xib之前的切换)
这篇学习的主要内容是Multiview,在我们学习iphone旋转的时候,介绍过多个view的使用方法,不过这里的view和旋转屏幕中所指的多个view是不同的,旋转屏幕中涉及到的多个view是在一个 ...
- ios成长之每日一遍(day 6)
toolBar上的View Switcher BIDAppDelegate.h #import <UIKit/UIKit.h> @class BIDSwitchViewController ...
- TextSwitcher(文本切换器)和ViewFlipper
1.TextSwitcher 使用: 应用分为三步: 1.得到 TextSwitcher 实例对象 TextSwitcher switcher = (TextSwitcher) findViewB ...
- [Android] 仿照 Last App Switcher 写的小程序
在Android众多工具类app中,Last App Switcher绝对算是一个让人用过就不会卸载的工具.LAS这个应用,它的功能很简单,就是通过一个浮动按钮实现在两个应用之间一键切换,但是非常 ...
- It's a Buck; It's a Boost, No! It's a Switcher!
It's a Buck; It's a Boost, No! It's a Switcher! Sanjaya Maniktala, National Semiconductor Corp., San ...
- 虾扯蛋:Android View动画 Animation不完全解析
本文结合一些周知的概念和源码片段,对View动画的工作原理进行挖掘和分析.以下不是对源码一丝不苟的分析过程,只是以搞清楚Animation的执行过程.如何被周期性调用为目标粗略分析下相关方法的执行细节 ...
- MVVM模式解析和在WPF中的实现(五)View和ViewModel的通信
MVVM模式解析和在WPF中的实现(五) View和ViewModel的通信 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二)数据绑定 M ...
- Android 判断一个 View 是否可见 getLocalVisibleRect(rect) 与 getGlobalVisibleRect(rect)
Android 判断一个 View 是否可见 getLocalVisibleRect(rect) 与 getGlobalVisibleRect(rect) [TOC] 这两个方法的区别 View.ge ...
- android 使用Tabhost 发生could not create tab content because could not find view with id 错误
使用Tabhost的时候经常报:could not create tab content because could not find view with id 错误. 总结一下发生错误的原因,一般的 ...
- SAP CRM 树视图(TREE VIEW)
树视图可以用于表示数据的层次. 例如:SAP CRM中的组织结构数据可以表示为树视图. 在SAP CRM Web UI的术语当中,没有像表视图(table view)或者表单视图(form view) ...
随机推荐
- leetcode191 Number of 1 Bit
题意:一个int类型正整数,求它的二进制形式有多少个1 思路:除2递归,可以解出,看了discuss里面有个解更牛,一行结束战斗,是用n&(n-1)再递归,其实并不是很懂怎么想出来这么做的,可 ...
- 微信小程序开发教程(二)创建第一个微信小程序
在安装完“微信Web开发者工具”之后,通过开发者的微信扫码进入后,如图. 点击“添加项目”,填入之前获得的AppID(无AppID可忽略),输入项目名称“Hello WXapplet”,选定本地文件夹 ...
- 和java面试不得不说的故事
一直都没有想到,可以有机会可以面试他人,很感谢现在的公司,给我不少的机会可以尝试从不同方面尝试一些工作,在入职现公司之前也作为面试者参加过不少面试,不过还好,面试通过率都还好,大部分是待遇谈不拢.现在 ...
- Problem J: 零起点学算法34——3n+1问题
#include<stdio.h> int main() { ; int n; scanf("%d",&n); ) { ==) n=n*+; else n/=; ...
- 苹果iOS系统下检查第三方APP是否安装及跳转启动
在iOS系统,使用Url Scheme框架在APP间互相跳转和传递数据,本文只介绍如果检测和跳转. Url Scheme框架 如果你想知道ios设备中是否安装QQ这个软件,我们可以通过一个简单方法判断 ...
- 【JVM】Myecplise自带的JVM大小调整,用于Junit等测试时使用
一般在使用Junit或者一个工具类的main方法执行时,在Myecplise中运行,并不会占用多大的堆空间.如果出现OutofMemory错误,调整MyEcplise自带的JVM大小. 在Myecpl ...
- tengine + lua 实现流量拷贝
环境搭建参考地址:http://www.cnblogs.com/cp-miao/p/7505910.html cp.lua local res1, res2, action action = ngx. ...
- Android ViewStub的使用方法
大家写项目的时候肯定会有一些东西提前写好,可是不到一定条件是不想让它显示出来的.我们可能的做法就是让它View.GONE 或View.INVISIBLE等到一定条件了在代码里面这设置View.VISI ...
- centos6.8下安装部署LNMP(备注:nginx1.8.0+php5.6.10+mysql5.6.12)
在平时运维工作中,经常需要用到LNMP应用框架.以下对LNMP环境部署记录下: 1)前期准备:为了安装顺利,建议先使用yum安装依赖库[root@opd ~]#yum install -y make ...
- solr6.6 solrJ索引富文本(word/pdf)文件
1.文件配置 在core下面新建lib文件夹,存放相关的jar包,如图所示: 修改solrconfig.xml <lib dir="${solr.install.dir:../../. ...