热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

【Android】_UI设计_图片滑动样式

目的:ImageSwitcher控件控制图片滑动样式(一)效果实现图:在图形切换控件中轮流显示,并有慢进慢出的动画效果(二)项目结构图

目的: ImageSwitcher控件控制图片滑动样式


(一) 效果实现图:

在图形切换控件中轮流显示,并有慢进慢出的动画效果
在这里插入图片描述

(二) 项目结构图:
  • 新建AndroidStudio项目
    在这里插入图片描述在这里插入图片描述
  • 引入内容
    anim:
    left_in、left_out、right_in、right_out
    Drawable:
    样式:shape_button_main.xml
    图片:tian1.png、tian2.png、tian3.png、movieback.png

(三)具体的编码实现
  1. 布局界面比较简单,加入ImageSwitcher组件,以及2个button,imageSwitcher.xml:
    在这里插入图片描述


<LinearLayout xmlns:android&#61;"http://schemas.android.com/apk/res/android"xmlns:tools&#61;"http://schemas.android.com/tools"android:layout_width&#61;"match_parent"android:layout_height&#61;"match_parent"android:orientation&#61;"vertical"android:gravity&#61;"center"android:background&#61;"#a98175"><ImageSwitcherandroid:id&#61;"&#64;&#43;id/is_1"android:layout_width&#61;"match_parent"android:layout_height&#61;"243dp"/><LinearLayoutandroid:layout_width&#61;"match_parent"android:layout_height&#61;"wrap_content"android:orientation&#61;"horizontal"android:paddingTop&#61;"15dp"><Buttonandroid:id&#61;"&#64;&#43;id/btn_previous"android:layout_width&#61;"0dip"android:layout_height&#61;"wrap_content"android:layout_weight&#61;"1"android:layout_marginLeft&#61;"15dp"android:layout_marginRight&#61;"15dp"android:background&#61;"&#64;drawable/shape_button_main"style&#61;"?android:attr/borderlessButtonStyle"android:text&#61;"上一张"android:textSize&#61;"18dp"android:textColor&#61;"#ffffff"/><Buttonandroid:id&#61;"&#64;&#43;id/btn_next"android:layout_width&#61;"0dip"android:layout_height&#61;"wrap_content"android:layout_weight&#61;"1"android:layout_marginLeft&#61;"15dp"android:layout_marginRight&#61;"15dp"android:background&#61;"&#64;drawable/shape_button_main"style&#61;"?android:attr/borderlessButtonStyle"android:text&#61;"下一张"android:textSize&#61;"18dp"android:textColor&#61;"#ffffff"/>LinearLayout>
LinearLayout>

  1. 引入 图片4张&#xff1a;把需要的图片复制到drawable中&#xff08;注意图片png形式且不要过大&#xff09;
    在这里插入图片描述
    在这里插入图片描述

  2. button样式1种&#xff1a;
    在这里插入图片描述
    在这里插入图片描述
    3.1 在drawable右键新建Drawabler esource file
    在这里插入图片描述
    3.2命名为shape_button_main&#xff1a;
    在这里插入图片描述
    3.3创建完成&#xff0c;并为其设置样式&#xff1a;
    在这里插入图片描述



<shape xmlns:android&#61;"http://schemas.android.com/apk/res/android"xmlns:tools&#61;"http://schemas.android.com/tools"android:shape&#61;"rectangle"tools:ignore&#61;"MissingDefaultResource"><solid android:color&#61;"#b36d61" /><strokeandroid:width&#61;"1dip"android:color&#61;"#b36d61" /><paddingandroid:bottom&#61;"10dp"android:left&#61;"10dp"android:right&#61;"10dp"android:top&#61;"10dp" /><corners android:radius&#61;"200dp" />shape>

3.4完成如图&#xff1a;在这里插入图片描述
4. 动态样式4种
在这里插入图片描述

4.1 在res右键添加Android Resource Directory文件夹&#xff1a;
在这里插入图片描述
4.2 命名为anim->选择type为anim&#xff1a;
在这里插入图片描述
4.3新建完成如图&#xff1a;
在这里插入图片描述
4.4 选中anim文件夹->右键添加Animation resource file样式&#xff1a;
在这里插入图片描述
4.5命名为left_in:
在这里插入图片描述
4.6重复添加left_out、right_in、right_out&#xff0c;完成如图&#xff1a;
在这里插入图片描述
4.7 自定义4种样式&#xff1a;
在这里插入图片描述

left_in&#xff1a;


<set xmlns:android&#61;"http://schemas.android.com/apk/res/android"><translateandroid:fromXDelta&#61;"-100%p"android:toXDelta&#61;"0"android:duration&#61;"600"/><alphaandroid:fromAlpha&#61;"0.1"android:toAlpha&#61;"1.0"android:duration&#61;"600"/>
set>

left_out:


<set xmlns:android&#61;"http://schemas.android.com/apk/res/android"><translateandroid:fromXDelta&#61;"0"android:toXDelta&#61;"-100%p"android:duration&#61;"600"/><alphaandroid:fromAlpha&#61;"0.1"android:toAlpha&#61;"1.0"android:duration&#61;"600"/>
set>

right_in:


<set xmlns:android&#61;"http://schemas.android.com/apk/res/android"><translateandroid:fromXDelta&#61;"100%p"android:toXDelta&#61;"0"android:duration&#61;"600"/><alphaandroid:fromAlpha&#61;"0.1"android:toAlpha&#61;"1.0"android:duration&#61;"600"/>
set>

right_out:


<set xmlns:android&#61;"http://schemas.android.com/apk/res/android"><translateandroid:fromXDelta&#61;"0"android:toXDelta&#61;"100%p"android:duration&#61;"600"/><alphaandroid:fromAlpha&#61;"0.1"android:toAlpha&#61;"1.0"android:duration&#61;"600"/>
set>

  1. 我的自定义colors&#xff1a;自定义应用顶部的颜色
    在这里插入图片描述
    效果图&#xff1a;
    在这里插入图片描述
  2. 主程序入口类imageSwitcherActivity.java

package com.example.cungu.myapplication3;import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;public class imageSwitcherActivity extends AppCompatActivity implements View.OnClickListener,ViewSwitcher.ViewFactory {private ImageSwitcher is_1;private Button btn_next;private Button btn_previous;private int image[]&#61;{R.drawable.tian1,R.drawable.tian2,R.drawable.tian3,R.drawable.movieback};//图片的id数组private int imageIndex&#61;0;//图片显示序列号&#64;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_image_switcher);is_1&#61;(ImageSwitcher) findViewById(R.id.is_1);btn_next&#61;(Button) findViewById(R.id.btn_next);btn_previous&#61;(Button) findViewById(R.id.btn_previous);btn_previous.setOnClickListener(this);btn_next.setOnClickListener(this);init(); //设置Factory}&#64;Overridepublic void onClick(View view) {if (view.getId()&#61;&#61;R.id.btn_next){imageIndex&#43;&#43;;if(imageIndex>3){imageIndex&#61;0;}is_1.setInAnimation(this,R.anim.left_in);is_1.setOutAnimation(this,R.anim.right_out);}else if(view.getId()&#61;&#61;R.id.btn_previous){imageIndex--;if(imageIndex<0){imageIndex&#61;image.length-1;}is_1.setInAnimation(this,R.anim.right_in);is_1.setOutAnimation(this,R.anim.left_out);}is_1.setImageResource(image[imageIndex]);}&#64;Overridepublic View makeView() {//实现viewFactory接口.生成imageviewImageView imageView&#61;new ImageView(this);return imageView;}private void init(){//初始化imageSwitchis_1.setFactory(this);is_1.setImageResource(image[imageIndex]);}
}

以上就是本文的全部内容&#xff0c;希望对大家的学习有所帮助~


推荐阅读
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板
    本文介绍了在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板的方法和步骤,包括将ResourceDictionary添加到页面中以及在ResourceDictionary中实现模板的构建。通过本文的阅读,读者可以了解到在Xamarin XAML语言中构建控件模板的具体操作步骤和语法形式。 ... [详细]
  • 带添加按钮的GridView,item的删除事件
    先上图片效果;gridView无数据时显示添加按钮,有数据时,第一格显示添加按钮,后面显示数据:布局文件:addr_manage.xml<?xmlve ... [详细]
  • 今天就跟大家聊聊有关怎么在Android应用中实现一个换肤功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根 ... [详细]
  • 后台获取视图对应的字符串
    1.帮助类后台获取视图对应的字符串publicclassViewHelper{将View输出为字符串(注:不会执行对应的ac ... [详细]
  • 有没有一种方法可以在不继承UIAlertController的子类或不涉及UIAlertActions的情况下 ... [详细]
  • IOS开发之短信发送与拨打电话的方法详解
    本文详细介绍了在IOS开发中实现短信发送和拨打电话的两种方式,一种是使用系统底层发送,虽然无法自定义短信内容和返回原应用,但是简单方便;另一种是使用第三方框架发送,需要导入MessageUI头文件,并遵守MFMessageComposeViewControllerDelegate协议,可以实现自定义短信内容和返回原应用的功能。 ... [详细]
  • Activiti7流程定义开发笔记
    本文介绍了Activiti7流程定义的开发笔记,包括流程定义的概念、使用activiti-explorer和activiti-eclipse-designer进行建模的方式,以及生成流程图的方法。还介绍了流程定义部署的概念和步骤,包括将bpmn和png文件添加部署到activiti数据库中的方法,以及使用ZIP包进行部署的方式。同时还提到了activiti.cfg.xml文件的作用。 ... [详细]
  • C#多线程解决界面卡死问题的完美解决方案
    当界面需要在程序运行中不断更新数据时,使用多线程可以解决界面卡死的问题。一个主线程创建界面,使用一个子线程执行程序并更新主界面,可以避免卡死现象。本文分享了一个例子,供大家参考。 ... [详细]
  • Java图形化计算器设计与实现
    本文介绍了使用Java编程语言设计和实现图形化计算器的方法。通过使用swing包和awt包中的组件,作者创建了一个具有按钮监听器和自定义界面尺寸和布局的计算器。文章还分享了在图形化界面设计中的一些心得体会。 ... [详细]
  • 开发笔记:(002)spring容器中bean初始化销毁时执行的方法及其3种实现方式
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了(002)spring容器中bean初始化销毁时执行的方法及其3种实现方式相关的知识,希望对你有一定的参考价值。 ... [详细]
author-avatar
袁甲2012_498
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有