首页 > 代码库 > Expert的View——StackView

Expert的View——StackView

StackView的使用效果:

技术分享

使用方法:

在Xml布局文件中使用:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="test.com.studiotest.StackViewActivity">

    <StackView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/stackView"
        android:orientation="horizontal"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="53dp" />
</RelativeLayout>
在Java 代码中使用:

 private StackView stackView;
    private Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context=this;
        setContentView(R.layout.activity_stack_view);
        stackView= (StackView) findViewById(R.id.stackView);
        stackView.setAdapter(new StackAdapter());
    }

    class StackAdapter extends BaseAdapter{

        private int[] images={R.drawable.gril,R.drawable.hourse,R.drawable.river,R.drawable.tree,R.drawable.women};
        @Override
        public int getCount() {
            return images.length;
        }

        @Override
        public Object getItem(int position) {
            return images[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView=new ImageView(context);
            imageView.setImageResource(images[position]);
            return imageView;
        }
    }

注意:

loopViews 的属性:  /**
     * Specifies if the animator should wrap from 0 to the end and vice versa
     * or have hard boundaries at the beginning and end
     */

在Android平台中,若想使用StackView,minSdkVersion 为11!

Expert的View——StackView