package com.example.shifteffect; import com.app.plugs.effect.EffectUtil; import com.app.plugs.effect.view.EffectView; import com.example.scrolleffect.R; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.AdapterView.OnItemSelectedListener; public class MainActivity extends Activity implements OnItemSelectedListener { // 展示渐变动效的容器,用于容纳渐变效果库的View控件 private LinearLayout container; // 渐变效果库的View控件类 private EffectView mView; // 文字资源(用于展示渐变切换) private String[] mTexts = { "今日新闻1", "今日新闻2", "今日新闻3" }; // 图片资源(用于展示渐变切换) private int[] mImages = { R.drawable.image_1, R.drawable.image_2, R.drawable.image_3 }; // 内容选项 private Spinner sp1; private ArrayAdapter<String> aa1; private String[] menu1 = { "内容:文字", "内容:图片" }; // 渐变时间选项 private Spinner sp2; private ArrayAdapter<String> aa2; private String[] menu2 = { "动时:300ms", "动时:1000ms", "动时:3000ms" }; // 渐变间隔选项 private Spinner sp3; private ArrayAdapter<String> aa3; private String[] menu3 = { "停时:3000ms", "停时:5000ms", "停时:10000ms" }; // 渐变效果选项 private Spinner sp4; private ArrayAdapter<String> aa4; private String[] menu4 = { "动效:向上", "动效:向下", "动效:向左", "动效:向右", "动效:旋转", "动效:大小", "动效:渐变" }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 初始化展示动效的容器 container = (LinearLayout) this.findViewById(R.id.container); // 初始化各个选项的内容 sp1 = (Spinner) findViewById(R.id.spinner1); aa1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, menu1); aa1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp1.setAdapter(aa1); sp1.setOnItemSelectedListener(this); sp2 = (Spinner) findViewById(R.id.spinner2); aa2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, menu2); aa2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp2.setAdapter(aa2); sp2.setOnItemSelectedListener(this); sp3 = (Spinner) findViewById(R.id.spinner3); aa3 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, menu3); aa3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp3.setAdapter(aa3); sp3.setOnItemSelectedListener(this); sp4 = (Spinner) findViewById(R.id.spinner4); aa4 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, menu4); aa4.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp4.setAdapter(aa4); sp4.setOnItemSelectedListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_main, menu); return true; } @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // 内容选项逻辑(可选择滚动文字或者图片) if (parent.getAdapter() == aa1) { container.removeAllViews(); switch (position) { case 0: // 初始化文字切换View对象 mView = EffectUtil.fillTexts(this, EffectView.ANI_UP, 30, mTexts); container.addView(mView); mView.start(); break; default: mView = EffectUtil.fillImages(this, EffectView.ANI_UP, mImages); container.addView(mView); mView.start(); break; } } // 渐变时间选项逻辑 if (parent.getAdapter() == aa2) { switch (position) { case 0: mView.setDuration(300); break; case 1: mView.setDuration(1000); break; default: mView.setDuration(3000); break; } } // 渐变间隔选项逻辑 if (parent.getAdapter() == aa3) { switch (position) { case 0: mView.setInterval(3000); break; case 1: mView.setInterval(5000); break; default: mView.setInterval(10000); break; } } // 渐变效果选项 if (parent.getAdapter() == aa4) { switch (position) { case 0: mView.setAnimation(EffectView.ANI_UP); // 往上滚动 break; case 1: mView.setAnimation(EffectView.ANI_DOWN); // 往下滚动 break; case 2: mView.setAnimation(EffectView.ANI_LEFT); // 往左滚动 break; case 3: mView.setAnimation(EffectView.ANI_RIGHT); // 往右滚动 break; case 4: mView.setAnimation(EffectView.ANI_ROTATE); // 旋转渐变 break; case 5: mView.setAnimation(EffectView.ANI_SCALE); // 大小渐变 break; default: mView.setAnimation(EffectView.ANI_FADE); // 消失渐变 break; } } } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="10dip" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Spinner android:id="@+id/spinner1" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Spinner android:id="@+id/spinner2" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Spinner android:id="@+id/spinner3" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <Spinner android:id="@+id/spinner4" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <LinearLayout android:id="@+id/container" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:gravity="center" /> </LinearLayout>
时间: 2024-09-08 05:03:02