android 图片横向滚动效果



好东西   转过来了  原文:http://blog.csdn.net/wdaming1986/article/details/6627068 

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

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

     

一、main.xml布局

[javascript]  view plain copy print ?
  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.   
  24.      <LinearLayout android:paddingLeft="12.0dip"  
  25.       android:layout_height="51.0dip" android:layout_width="1sp"  
  26.       android:background="#000000">  
  27.      </LinearLayout>  
  28.   
  29.      <ImageButton android:id="@+id/new_doc"  
  30.       android:layout_width="59.0dip" android:layout_height="51.0dip"  
  31.       android:scaleType="centerInside" android:background="@drawable/icon">  
  32.      </ImageButton>  
  33.   
  34.      <LinearLayout android:layout_height="51.0dip"  
  35.       android:layout_width="1sp" android:background="#000000">  
  36.      </LinearLayout>  
  37.   
  38.      <ImageButton android:id="@+id/filter_doc"  
  39.       android:layout_width="59.0dip" android:layout_height="51.0dip"  
  40.       android:scaleType="centerInside" android:background="@drawable/icon">  
  41.      </ImageButton>  
  42.   
  43.   
  44.      <LinearLayout android:layout_height="51.0dip"  
  45.       android:layout_width="1sp" android:background="#000000">  
  46.      </LinearLayout>  
  47.   
  48.    
  49.   
  50.      <ImageButton android:id="@+id/multiselect_doc"  
  51.       android:layout_width="59.0dip" android:layout_height="51.0dip"  
  52.       android:scaleType="centerInside" android:background="@drawable/icon">  
  53.      </ImageButton>  
  54.   
  55.   
  56.      <LinearLayout android:layout_height="51.0dip"  
  57.       android:layout_width="1sp" android:background="#000000">  
  58.      </LinearLayout>  
  59.   
  60.      <ImageButton android:id="@+id/delete_doc"  
  61.       android:layout_width="59.0dip" android:layout_height="51.0dip"  
  62.       android:scaleType="centerInside" android:background="@drawable/icon">  
  63.      </ImageButton>  
  64.   
  65.      <LinearLayout android:layout_height="51.0dip"  
  66.       android:layout_width="1sp" android:background="#000000">  
  67.      </LinearLayout>  
  68.   
  69.      <ImageButton android:id="@+id/property_doc" android:visibility="gone"  
  70.       android:layout_width="59.0dip" android:layout_height="51.0dip"  
  71.       android:scaleType="centerInside" android:background="@drawable/icon">  
  72.      </ImageButton>  
  73.   
  74.      <LinearLayout android:layout_height="51.0dip"  
  75.       android:layout_width="1sp" android:background="#000000">  
  76.      </LinearLayout>  
  77.   
  78.      <ImageButton android:id="@+id/sort_doc"  
  79.       android:layout_width="59.0dip" android:layout_height="51.0dip"  
  80.       android:scaleType="centerInside" android:background="@drawable/icon">  
  81.      </ImageButton>  
  82.   
  83.   
  84.      <LinearLayout android:layout_height="51.0dip"  
  85.       android:layout_width="1sp" android:background="#000000">  
  86.      </LinearLayout>  
  87.   
  88.      <ImageButton android:id="@+id/send_doc"   
  89.       android:layout_width="59.0dip" android:layout_height="51.0dip"  
  90.       android:scaleType="centerInside" android:background="@drawable/icon">  
  91.      </ImageButton>  
  92.     </LinearLayout>  
  93.     <ImageView android:layout_width="wrap_content"   
  94.      android:layout_height="51.0dip" android:src="@drawable/icon" />  
  95.   
  96.    </LinearLayout>  
  97.   </HorizontalScrollView>  
  98. </LinearLayout>  


二、MainActivity类中的代码:

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


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

[html]  view plain copy print ?
  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" />  

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值