当前位置: 首页 > news >正文

深圳网站优化技巧/网站模板哪里好

深圳网站优化技巧,网站模板哪里好,廊坊网站建设多少钱,dz可以做视频网站吗本文实例讲述了Android开发之ViewSwitcher用法。分享给大家供大家参考,具体如下:android.widget.ViewSwitcher是ViewAnimator的子类,用于在两个View之间切换,但每次只能显示一个View。ViewSwitcher的addView函数的代码如下&#x…

本文实例讲述了Android开发之ViewSwitcher用法。分享给大家供大家参考,具体如下:

android.widget.ViewSwitcher是ViewAnimator的子类,用于在两个View之间切换,但每次只能显示一个View。

ViewSwitcher的addView函数的代码如下:

/**

* {@inheritDoc}

*

* @throws IllegalStateException if this switcher already contains two children

*/

@Override

public void addView(View child, int index, ViewGroup.LayoutParams params) {

if (getChildCount() >= 2) {

throw new IllegalStateException("Can't add more than 2 views to a ViewSwitcher");

}

super.addView(child, index, params);

}

可以看出,若View的数量超过两个,会抛出异常:java.lang.IllegalStateException,打印 "Can't add more than 2 views to a ViewSwitcher" 。你可以使用ViewSwitcher的factory创建View或添加自己创建的View。

下面用一个例子介绍一下ViewSwitcher的用法。

布局文件:activity_main.xml

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

tools:context=".MainActivity" >

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

android:id="@+id/prev"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="previous" />

android:id="@+id/next"

android:layout_width="0dp"

android:layout_height="wrap_content"

android:layout_weight="1"

android:text="next" />

android:id="@+id/viewswitcher"

android:layout_width="match_parent"

android:layout_height="wrap_content" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/ic_launcher" />

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:gravity="center"

android:orientation="vertical" >

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="- Button 2 -" />

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="LinearLayout 2" />

Activity的代码:

package com.example.AndroidTest;

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.widget.Button;

import android.widget.ViewSwitcher;

public class MyActivity extends Activity {

Button buttonPrev, buttonNext;

ViewSwitcher viewSwitcher;

Animation slide_in_left, slide_out_right;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

buttonPrev = (Button) findViewById(R.id.prev);

buttonNext = (Button) findViewById(R.id.next);

viewSwitcher = (ViewSwitcher) findViewById(R.id.viewswitcher);

slide_in_left = AnimationUtils.loadAnimation(this,

android.R.anim.slide_in_left);

slide_out_right = AnimationUtils.loadAnimation(this,

android.R.anim.slide_out_right);

viewSwitcher.setInAnimation(slide_in_left);

viewSwitcher.setOutAnimation(slide_out_right);

buttonPrev.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View arg0) {

viewSwitcher.showPrevious();

}

});

buttonNext.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View arg0) {

viewSwitcher.showNext();

}

});

;

}

}

实现效果图:

82ce53b0bc56656edac9dd5fd67f9fed.png

使用ViewSwitcher的setFactory设置切换的View,分为两步。

第一步:获得ViewSwithcer的实例

switcher = (ViewSwitcher) findViewById(R.id.viewSwitcher);

第二部:实现接口ViewFactory

switcher.setFactory(new ViewFactory()

{

@Override

public View makeView()

{

return inflater.inflate(R.layout.slidelistview, null);

}

});

希望本文所述对大家Android程序设计有所帮助。

http://www.lbrq.cn/news/1324729.html

相关文章:

  • 团购网站模板下载/宽带推广方案
  • 选择做华为网站的目的和意义/惠州优化怎么做seo
  • 湖南网红网站建设有限公司/seo网站推广企业
  • 前端开发是做网站的吗/app推广拉新渠道
  • 淮北建设机械网站/深圳网络推广网络
  • 企业网站结构/seo从入门到精通
  • 构建网站的步骤/今天最近的新闻
  • 免费建设企业网站/网站建设技术
  • 建设公司需要网站吗/少儿编程培训机构排名前十
  • 深圳企业网站制作设计/发稿服务
  • 2008服务器网站/网站创建流程
  • 美国建设新闻网站/aso优化怎么做
  • 做汽车行业必须注册际零件网站/网站推广做什么
  • lol福利wordpress/整站优化案例
  • 微信连接微网站/重庆seo招聘
  • 网络推广图片大全/网站怎样优化seo
  • 做羞羞的事视频网站/百度指数分析工具
  • 华侨城网站建设/365优化大师软件下载
  • the7做的网站/互联网项目推广平台有哪些
  • 手机视频网站搭建/浏览器下载大全
  • 销售网站建设常遇到的问题/推广赚钱app哪个靠谱
  • 基于java的视频网站开发/搜索引擎推广排名
  • 门户网站兴化建设局 金/seo编辑是干什么的
  • 网上赚钱的副业/百度首页排名优化哪家专业
  • 大连旅顺口区疫情最新消息/武汉seo群
  • 福田蒙派克s/seo推广网址
  • 嘉兴自助建网站/搜索引擎营销的概念及特点
  • 视频直播网站开发/刷赞抖音推广网站
  • 爱用建站平台的优势/个人网站设计作品
  • 建程网会员共享/武汉seo系统
  • SQL 怎么学?
  • 飞书 —— 多维表格 —— AI生成
  • 计算器4.0:新增页签功能梳理页面,通过IO流实现在用户本地存储数据
  • 数据结构【红黑树】
  • 飞鹤困局:增长神话的裂痕
  • C语言:20250728学习(指针)