Spinner Animation

简介: java public class xiala extends Activity{ private static final String[] countriesStr = { "AA", "BB", "CC", "DD" }; private TextView myTextView; private Spinner mySpinner; priva

 


java

public class xiala extends Activity
{
  private static final String[] countriesStr =
  { "AA", "BB", "CC", "DD" };
  private TextView myTextView;
  private Spinner mySpinner;
  private ArrayAdapter<String> adapter;
  Animation myAnimation;

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    /* 载入main.xml Layout */
    setContentView(R.layout.main);

    /* 以findViewById()取得对象 */
    myTextView = (TextView) findViewById(R.id.myTextView);
    mySpinner = (Spinner) findViewById(R.id.mySpinner);

    adapter = new ArrayAdapter<String>(this,
        android.R.layout.simple_spinner_item, countriesStr);
    /* myspinner_dropdown为自定义下拉菜单模式定义在res/layout目录下 */
    adapter.setDropDownViewResource(R.layout.myspinner);

    /* 将ArrayAdapter添加Spinner对象中 */
    mySpinner.setAdapter(adapter);

    /* 将mySpinner添加OnItemSelectedListener */
    mySpinner.setOnItemSelectedListener
     (new Spinner.OnItemSelectedListener()
    {
      @Override
      public void onItemSelected
       (AdapterView<?> arg0, View arg1, int arg2,
          long arg3)
      {
        /* 将所选mySpinner的值带入myTextView中 */
        myTextView.setText("您选择的是" + countriesStr[arg2]);
        /* 将mySpinner显示 */
        arg0.setVisibility(View.VISIBLE);
      }

      @Override
      public void onNothingSelected(AdapterView<?> arg0)
      {
        // TODO Auto-generated method stub
      }
    });

    /* 取得Animation定义在res/anim目录下 */
    myAnimation = AnimationUtils.loadAnimation(this, R.anim.my_anim);

    /* 将mySpinner添加OnTouchListener */
    mySpinner.setOnTouchListener(new Spinner.OnTouchListener()
    {

      @Override
      public boolean onTouch(View v, MotionEvent event)
      {
        /* 将mySpinner运行Animation */
        v.startAnimation(myAnimation);
        /* 将mySpinner隐藏 */
        v.setVisibility(View.INVISIBLE);
        return false;
      }

    });

    mySpinner.setOnFocusChangeListener(new Spinner.OnFocusChangeListener()
    {
      @Override
      public void onFocusChange(View v, boolean hasFocus)
      {
        // TODO Auto-generated method stub
      }
    });
  }
}
main.xml

<?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"
  android:background="@drawable/white"
  >
  <TextView  
  android:id="@+id/myTextView"
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:text="@string/title"
  android:textColor="@drawable/black"
  >
  </TextView>
  <Spinner 
  android:id="@+id/mySpinner"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content" 
  >
  </Spinner>
</LinearLayout>
anim

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
  <translate 
  android:fromXDelta="0" 
  android:toXDelta="-100%p" 
  android:duration="300"
  >
  </translate>
  <alpha 
  android:fromAlpha="1.0" 
  android:toAlpha="0.0" 
  android:duration="300">
  </alpha>
</set>
myspinner.xml

<?xml version="1.0" encoding="utf-8"?>  
<TextView  
 xmlns:android="http://schemas.android.com/apk/res/android"  
 android:id="@+id/text1"  
 android:layout_width="wrap_content"  
 android:layout_height="24sp"  
 android:singleLine="true" 
 style="?android:attr/spinnerDropDownItemStyle" />  




















目录
相关文章
|
Android开发
解决圆形进度条ProgressBar的几个问题
Android自带的Progressbar默认就是圆形的,可以通过设置style属性 style="?android:attr/progressBarStyleHorizontal" 复制代码 这样就能变成条状进度条,如下: <ProgressBar android:layout_width="match_parent" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal"/>
1291 0
|
3月前
|
JavaScript 前端开发
fadeIn
【9月更文挑战第27天】
42 5
|
5月前
|
前端开发 JavaScript
【HTML+CSS+JavaScript】Animated Navigation
【HTML+CSS+JavaScript】Animated Navigation
25 0
|
7月前
|
数据处理 C# UED
42.c#:progressbar控件
42.c#:progressbar控件
76 1
|
前端开发
transition和animation的区别
transition和animation的区别
|
XML API Android开发
Android 属性动画Property Animation(中)
ValueAnimator指定整形、浮点型或者颜色值作为动画值,在一定时间内平滑过渡。可以通过ofInt(),ofFloat(),或ofObject()来或得一个ValueAnimator
104 0
|
前端开发
scroll-view实现不了滑动效果
scroll-view实现不了滑动效果
274 0
|
API Android开发
【Android 属性动画】属性动画 Property Animation 与 视图动画 View Animation 区别
【Android 属性动画】属性动画 Property Animation 与 视图动画 View Animation 区别
137 0