Android image horizontal scrolling Effect Original [android Evolution 5]

Source: Internet
Author: User

 

Recently, a colleague has made an effect: horizontal picture arrangement, horizontal scrolling, and clicking an image trigger event. gallery can also achieve this effect. Now I use ImageButton to implement it, you can use HorizontalScrollView to package the layout file in the xml file. Now I will share the Code with you. First, let's take a look at the effect:

The entire queue is on the left: The entire queue is in the middle: The entire queue is on the right:

 

 


1. main. xml Layout

 

<? Xml version = "1.0" encoding = "UTF-8"?>

<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"

Android: orientation = "vertical"

Android: layout_width = "fill_parent"

Android: layout_height = "fill_parent"

>

<HorizontalScrollView android: id = "@ + id/HorizontalScrollView01"

Android: fadingEdgeLength = "0.0dip" android: background = "# 5B5B5B"

Android: layout_width = "fill_parent" android: scrollbars = "none"

Android: layout_height = "fill_parent">

<LinearLayout android: layout_width = "wrap_content"

Android: id = "@ + id/toolbar_items" android: paddingBottom = "7.0dip"

Android: orientation = "horizontal" android: layout_height = "wrap_content"

Android: paddingTop = "7.0dip">

<ImageView android: layout_height = "51.0dip"

Android: layout_width = "wrap_content" android: src = "@ drawable/icon"/>

<LinearLayout android: layout_width = "wrap_content"

Android: background = "# ffffff" android: layout_height = "51.0dip">

<ImageButton android: background = "@ drawable/icon"

Android: layout_width = "591_dip" android: layout_height = "51.0dip"

Android: scaleType = "centerInside" android: id = "@ + id/back_main">

</ImageButton>

 

<LinearLayout android: paddingLeft = "12.0dip"

Android: layout_height = "51.0dip" android: layout_width = "1sp"

Android: background = "#000000">

</LinearLayout>

 

<ImageButton android: id = "@ + id/new_doc"

Android: layout_width = "591_dip" android: layout_height = "51.0dip"

Android: scaleType = "centerInside" android: background = "@ drawable/icon">

</ImageButton>

 

<LinearLayout android: layout_height = "51.0dip"

Android: layout_width = "1sp" android: background = "#000000">

</LinearLayout>

 

<ImageButton android: id = "@ + id/filter_doc"

Android: layout_width = "591_dip" android: layout_height = "51.0dip"

Android: scaleType = "centerInside" android: background = "@ drawable/icon">

</ImageButton>

 

 

<LinearLayout android: layout_height = "51.0dip"

Android: layout_width = "1sp" android: background = "#000000">

</LinearLayout>

 

 

<ImageButton android: id = "@ + id/multiselect_doc"

Android: layout_width = "591_dip" android: layout_height = "51.0dip"

Android: scaleType = "centerInside" android: background = "@ drawable/icon">

</ImageButton>

 

 

<LinearLayout android: layout_height = "51.0dip"

Android: layout_width = "1sp" android: background = "#000000">

</LinearLayout>

 

<ImageButton android: id = "@ + id/delete_doc"

Android: layout_width = "591_dip" android: layout_height = "51.0dip"

Android: scaleType = "centerInside" android: background = "@ drawable/icon">

</ImageButton>

 

<LinearLayout android: layout_height = "51.0dip"

Android: layout_width = "1sp" android: background = "#000000">

</LinearLayout>

 

<ImageButton android: id = "@ + id/property_doc" android: visibility = "gone"

Android: layout_width = "591_dip" android: layout_height = "51.0dip"

Android: scaleType = "centerInside" android: background = "@ drawable/icon">

</ImageButton>

 

<LinearLayout android: layout_height = "51.0dip"

Android: layout_width = "1sp" android: background = "#000000">

</LinearLayout>

 

<ImageButton android: id = "@ + id/sort_doc"

Android: layout_width = "591_dip" android: layout_height = "51.0dip"

Android: scaleType = "centerInside" android: background = "@ drawable/icon">

</ImageButton>

 

 

<LinearLayout android: layout_height = "51.0dip"

Android: layout_width = "1sp" android: background = "#000000">

</LinearLayout>

 

<ImageButton android: id = "@ + id/send_doc"

Android: layout_width = "591_dip" android: layout_height = "51.0dip"

Android: scaleType = "centerInside" android: background = "@ drawable/icon">

</ImageButton>

</LinearLayout>

<ImageView android: layout_width = "wrap_content"

Android: layout_height = "51.0dip" android: src = "@ drawable/icon"/>

 

</LinearLayout>

</HorizontalScrollView>

</LinearLayout>

 

Ii. MainActivity code:

 

Package com.cn. android;

 

Import android. app. Activity;

Import android. content. Intent;

Import android. OS. Bundle;

Import android. view. View;

Import android. view. animation. Animation;

Import android. view. animation. AnimationUtils;

Import android. view. animation. OvershootInterpolator;

Import android. widget. ImageButton;

Import android. widget. LinearLayout;

 

Public class MainActivity extends Activity {

/** Called when the activity is first created .*/

@ Override

Public void onCreate (Bundle savedInstanceState ){

Super. onCreate (savedInstanceState );

 

SetContentView (R. layout. main );

// Open the effect animation of the entire queue chart of the project

 

 

LinearLayout toolbarLayout = (LinearLayout) findViewById (R. id. toolbar_items );

Animation animation = AnimationUtils

. LoadAnimation (this, R. anim. toolbar );

Animation. setInterpolator (new OvershootInterpolator ());

// Animation. setInterpolator (new BounceInterpolator ());

ToolbarLayout. startAnimation (animation );

InitToolbarBtn (); // initialize ImageButton

}

 

 

 

 

// Response button click event

 

 

Private void initToolbarBtn (){

ImageButton backmain = (ImageButton) findViewById (R. id. back_main );

Backmain. setOnClickListener (new View. OnClickListener (){

Public void onClick (View v ){

Intent I = getIntent ();

SetResult (RESULT_CANCELED, I );

Finish ();

}

});

 

ImageButton newdoc = (ImageButton) findViewById (R. id. new_doc );

Newdoc. setOnClickListener (new View. OnClickListener (){

Public void onClick (View v ){

// Write the method you want to implement

}

});

}

}

 

3. Customize the animation to scroll from left to right: Create a folder named anim under res and create toolbar. xml <? Xml version = "1.0" encoding = "UTF-8"?>; The purpose is to have an animation when opening the Program Screen.

 

<Translate

Android: duration = "700" android: fromXDelta = "100.0% p" android: toXDelta = "0.0"

Xmlns: android = "http://schemas.android.com/apk/res/android"/>

 




From Daming zeroson's android learning history

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.