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="59.0dip" 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="59.0dip" 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="59.0dip" 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="59.0dip" 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="59.0dip" 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="59.0dip" 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="59.0dip" 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="59.0dip" 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); // The animation linearlayout toolbarlayout = (linearlayout) findviewbyid (R. id. toolbar_items); animation = animationutils. loadanimation (this, R. anim. toolbar); animation. setinterpolator (New overshootinterpolator (); // animation. setinterpolator (New bounceinterpolator (); toolbarlayout. startanimation (animation); inittoolbarbtn (); // initialize imagebutton} // click the 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" />