ScrollingImageView 横向滚动的image view
来源:互联网 发布:mac 版cad导入字体库 编辑:程序博客网 时间:2024/05/23 10:38
ScrollingImageView 是一个横向一直滚动的图片,犹如过火车的车窗外效果;大家可以想象一下是个什么样的场景;
网上也有不少的示例,我呢也就照着别人的照着别人说的做,能实现就好。
因为该控件是第三方的,我就不深入研究,毕竟使用场景还是有限的,不关注具体实现,只关注实现的效果。是不是我们想要。
具体使用如下:
一 。配置
1 . 在app_build.gradle 的dependencie添加
compile 'com.github.Q42:AndroidScrollingImageView:1.2'
注意sdk最低不的要求 必须高于15
2 .在工程的 build.gradle 的allprojects 添加
maven { url "https://jitpack.io"}
二 在我们的activity 的xml 里和其他控件一样使用。因为是自己定义的控件,那么我们声明是自己定义所以必须加上这样一句话
xmlns:scrolling_image_view="http://schemas.android.com/apk/res-auto"
需要设置两个下边属性
//设置滚动的速度 scrolling_image_view:speed="2dp" //设置需要滚动的图片类容 scrolling_image_view:src="@drawable/scrolling_background"
三 在activity 的代码里使用需要调用者两个方法
scrollingBackground.stop();
scrollingBackground.start();
下面看具体代码
xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:scrolling_image_view="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" tools:context="com.example.administrator.domepoject.MainActivity"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent"> <com.q42.android.scrollingimageview.ScrollingImageView android:id="@+id/siv" android:layout_width="match_parent" android:layout_height="match_parent" scrolling_image_view:speed="2dp" scrolling_image_view:src="@drawable/scrolling_background" /> <ImageView android:layout_marginTop="40dp" android:src="@drawable/van" android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </FrameLayout></LinearLayout>
activity
package com.example.administrator.domepoject;import android.animation.AnimatorSet;import android.animation.ObjectAnimator;import android.annotation.SuppressLint;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.webkit.JavascriptInterface;import android.webkit.WebChromeClient;import android.webkit.WebSettings;import android.webkit.WebView;import android.webkit.WebViewClient;import android.widget.ImageView;import android.widget.Toast;import com.q42.android.scrollingimageview.ScrollingImageView;public class MainActivity extends AppCompatActivity { ImageView image; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ScrollingImageView scrollingBackground = (ScrollingImageView) findViewById(R.id.siv); scrollingBackground.stop(); scrollingBackground.start(); image= (ImageView) findViewById(R.id.image); one(); } private void one(){ ObjectAnimator animator1 = ObjectAnimator.ofFloat(image, "translationY", 0, 20f); ObjectAnimator animator2 = ObjectAnimator.ofFloat(image, "translationX", 0, 200f); animator2.setStartDelay(2000); AnimatorSet set = new AnimatorSet(); set.playTogether(animator1, animator2); set.setDuration(3000); set.start(); }}
以上就可以达到我们想要的效果。
为了更加美观。我们可以在布局文件里使用帧布局,嵌套多层不同速度的图片,达到更加完美的视觉效果
0 0
- ScrollingImageView 横向滚动的image view
- 图片循环滚动控件ScrollingImageView
- 横向滚动的ListView
- 横向滚动的tableview
- 微信小程序 scroll-view横向滚动 坑
- 简单实现自定义横向滚动选择View
- 微信小程序 image组件的mode属性 以及 图片出现横向滚动轴
- 微信小程序 image组件的mode属性 以及 图片出现横向滚动轴
- 基于view的复用的自定义横向滚动的Viewgroup
- Android中View的事件体系(3)——自定义横向滚动viewGroup
- 自定义view二--可以横向滚动且只显示两张半的imageview
- 文字横向滚动的实现
- 横向滚动条的设置
- 文字横向滚动的实现
- 横向ListView的自动滚动
- 文字横向滚动的TextView
- 微信小程序-横向滑动scroll-view隐藏滚动条
- 微信小程序-scroll-view横向滚动和上拉加载
- hdu3709 Balanced Number(数位dp)
- equals方法的重写
- 大数系列——大数除法以及求模
- POJ 3261 Milk Patterns , Hash
- 软件工程——需求分析
- ScrollingImageView 横向滚动的image view
- Linux-CentOS XAMPP Apache 启用GZIP压缩功能 mod_deflate的安装配置
- CSU-1111 三家人
- createEvent模拟mouseMove方法
- 监听request session servletContext的创建与销毁
- Linux常见锁比较--自旋锁、互斥锁、信号量、临界区
- JAVA程序
- H264 笔记
- ProtoBuf开发者指南大全(Google Protocol Buffer协议)