当前位置:   article > 正文

android 图片横向滚动效果 原创【安卓进化五】_安卓横向滑动动画

安卓横向滑动动画

   近日有个同事要做一个效果:图片横向排列,而且可以横向滚动,而且能点击图片触发事件,用gallery也可以实现这个效果,现在我用ImageButton来实现,在xml文件中用HorizontalScrollView包起来这个布局文件就可以了。现把代码分享给大家;先贴图让大家看一眼效果:

整个队列在左边:                 整个队列在中间:                整个队列在右边:

     

一、main.xml布局

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. >
  7. <HorizontalScrollView android:id="@+id/HorizontalScrollView01"
  8. android:fadingEdgeLength="0.0dip" android:background="#5B5B5B"
  9. android:layout_width="fill_parent" android:scrollbars="none"
  10. android:layout_height="fill_parent">
  11. <LinearLayout android:layout_width="wrap_content"
  12. android:id="@+id/toolbar_items" android:paddingBottom="7.0dip"
  13. android:orientation="horizontal" android:layout_height="wrap_content"
  14. android:paddingTop="7.0dip">
  15. <ImageView android:layout_height="51.0dip"
  16. android:layout_width="wrap_content" android:src="@drawable/icon" />
  17. <LinearLayout android:layout_width="wrap_content"
  18. android:background="#ffffff" android:layout_height="51.0dip">
  19. <ImageButton android:background="@drawable/icon"
  20. android:layout_width="59.0dip" android:layout_height="51.0dip"
  21. android:scaleType="centerInside" android:id="@+id/back_main">
  22. </ImageButton>
  23. <LinearLayout android:paddingLeft="12.0dip"
  24. android:layout_height="51.0dip" android:layout_width="1sp"
  25. android:background="#000000">
  26. </LinearLayout>
  27. <ImageButton android:id="@+id/new_doc"
  28. android:layout_width="59.0dip" android:layout_height="51.0dip"
  29. android:scaleType="centerInside" android:background="@drawable/icon">
  30. </ImageButton>
  31. <LinearLayout android:layout_height="51.0dip"
  32. android:layout_width="1sp" android:background="#000000">
  33. </LinearLayout>
  34. <ImageButton android:id="@+id/filter_doc"
  35. android:layout_width="59.0dip" android:layout_height="51.0dip"
  36. android:scaleType="centerInside" android:background="@drawable/icon">
  37. </ImageButton>
  38. <LinearLayout android:layout_height="51.0dip"
  39. android:layout_width="1sp" android:background="#000000">
  40. </LinearLayout>
  41. <ImageButton android:id="@+id/multiselect_doc"
  42. android:layout_width="59.0dip" android:layout_height="51.0dip"
  43. android:scaleType="centerInside" android:background="@drawable/icon">
  44. </ImageButton>
  45. <LinearLayout android:layout_height="51.0dip"
  46. android:layout_width="1sp" android:background="#000000">
  47. </LinearLayout>
  48. <ImageButton android:id="@+id/delete_doc"
  49. android:layout_width="59.0dip" android:layout_height="51.0dip"
  50. android:scaleType="centerInside" android:background="@drawable/icon">
  51. </ImageButton>
  52. <LinearLayout android:layout_height="51.0dip"
  53. android:layout_width="1sp" android:background="#000000">
  54. </LinearLayout>
  55. <ImageButton android:id="@+id/property_doc" android:visibility="gone"
  56. android:layout_width="59.0dip" android:layout_height="51.0dip"
  57. android:scaleType="centerInside" android:background="@drawable/icon">
  58. </ImageButton>
  59. <LinearLayout android:layout_height="51.0dip"
  60. android:layout_width="1sp" android:background="#000000">
  61. </LinearLayout>
  62. <ImageButton android:id="@+id/sort_doc"
  63. android:layout_width="59.0dip" android:layout_height="51.0dip"
  64. android:scaleType="centerInside" android:background="@drawable/icon">
  65. </ImageButton>
  66. <LinearLayout android:layout_height="51.0dip"
  67. android:layout_width="1sp" android:background="#000000">
  68. </LinearLayout>
  69. <ImageButton android:id="@+id/send_doc"
  70. android:layout_width="59.0dip" android:layout_height="51.0dip"
  71. android:scaleType="centerInside" android:background="@drawable/icon">
  72. </ImageButton>
  73. </LinearLayout>
  74. <ImageView android:layout_width="wrap_content"
  75. android:layout_height="51.0dip" android:src="@drawable/icon" />
  76. </LinearLayout>
  77. </HorizontalScrollView>
  78. </LinearLayout>


二、MainActivity类中的代码:

  1. package com.cn.android;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.animation.Animation;
  7. import android.view.animation.AnimationUtils;
  8. import android.view.animation.OvershootInterpolator;
  9. import android.widget.ImageButton;
  10. import android.widget.LinearLayout;
  11. public class MainActivity extends Activity {
  12. /** Called when the activity is first created. */
  13. @Override
  14. public void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.main);
  17. //打开项目整个队列图进入的效果动画
  18. LinearLayout toolbarLayout = (LinearLayout) findViewById(R.id.toolbar_items);
  19. Animation animation = AnimationUtils
  20. .loadAnimation(this, R.anim.toolbar);
  21. animation.setInterpolator(new OvershootInterpolator());
  22. // animation.setInterpolator(new BounceInterpolator());
  23. toolbarLayout.startAnimation(animation);
  24. initToolbarBtn();//初始化ImageButton
  25. }
  26. //响应按钮点击事件
  27. private void initToolbarBtn() {
  28. ImageButton backmain = (ImageButton) findViewById(R.id.back_main);
  29. backmain.setOnClickListener(new View.OnClickListener() {
  30. public void onClick(View v) {
  31. Intent i = getIntent();
  32. setResult(RESULT_CANCELED, i);
  33. finish();
  34. }
  35. });
  36. ImageButton newdoc = (ImageButton) findViewById(R.id.new_doc);
  37. newdoc.setOnClickListener(new View.OnClickListener() {
  38. public void onClick(View v) {
  39. //写上自己要实现的方法
  40. }
  41. });
  42. }
  43. }


三、自定义动画实现从左向右滚动:在res下面建个文件夹名字anim,下建立toolbar.xml<?xml version="1.0" encoding="UTF-8"?>;目的是打开程序画面的时候有个动画的效果

  1. <translate
  2. android:duration="700" android:fromXDelta="100.0%p" android:toXDelta="0.0"
  3. xmlns:android="http://schemas.android.com/apk/res/android" />


 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/466561
推荐阅读
相关标签
  

闽ICP备14008679号