Spinner控件的使用以及动画的使用

main.xml

 

animation.xml

 

 

动画的显示:

动画有四种类型显示:alpha(透明度),scale(缩放),translate(位置),rotate(旋转)。

 

spinnerdropdown.xml

 

adapter.setDropDownViewResource(R.layout.spinnerdropdown);

针对下拉菜单中的Textiew进行设置。

SpinnerActivity.java

package com.itxinke.www; import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.TextView; public class SpinnerActivity extends Activity { /** Called when the activity is first created. */ private static final String[] location = { "北京","天津","上海","深圳" }; private Spinner spinner; private TextView textView; private ArrayAdapter adapter; Animation animation; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView)findViewById(R.id.textView); spinner = (Spinner)findViewById(R.id.spinner); adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_dropdown_item,location); adapter.setDropDownViewResource(R.layout.spinnerdropdown); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub textView.setText(location[arg2]); arg0.setVisibility(View.VISIBLE); } @Override public void onNothingSelected(AdapterView arg0) { // TODO Auto-generated method stub } }); animation = AnimationUtils.loadAnimation(this, R.layout.animation); spinner.setOnTouchListener(new Spinner.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub v.startAnimation(animation); return false; } }); } } 

 

你可能感兴趣的:(业余android)