评级界面
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rating="3"
android:numStars="5"
android:stepSize="0.5"
android:id="@+id/star"/>
点击事件
ratingBar=(RatingBar)findViewById(R.id.star);
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
Toast.makeText(MainActivity.this,"得分:"+rating,Toast.LENGTH_LONG).show();
}
});
TextSwitcher文本切换,import android.widget.FrameLayout.LayoutParams;一般设置listview的宽高等参数用的是android.widget.AbsListView.LayoutParams
android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="match_parent" >
图片切换
android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="match_parent" >
实现类都差不多
//switcher = (TextSwitcher) findViewById(R.id.switcher);
switcher = (ImageSwitcher) findViewById(R.id.switcher);
// 设置建立工厂类,返回显示的内部组件
switcher.setFactory(new ViewFactory() {
@Override
public View makeView() {
// 建立要显示文字的textview
/* TextView text = new TextView(MainActivity.this);
text.setTextColor(Color.BLACK);
text.setTextSize(16);
text.setBackgroundColor(Color.WHITE);
text.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
return text;*/
ImageView img=new ImageView(MainActivity.this);
img.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
return img;
}
});
// 处理内容
//switcher.setText(allTexts[index]);
switcher.setImageResource(allImgs[index]);
// 设置动画效果, 系统动画功能不完善,一般都满足不了开发的需求, 因此这里完成一个自定义的平移动画
// switcher.setInAnimation(AnimationUtils.loadAnimation(this,
// android.R.anim.slide_in_left));
// switcher.setOutAnimation(AnimationUtils.loadAnimation(this,
// android.R.anim.slide_out_right));
// 加入触屏监听, 使用该监听的前提是, 组件必须先加入过OnClickListener
switcher.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
switcher.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// 可以支持多点操作,但此程序只设置单点操作
if (event.getPointerCount() == 1) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// 手指刚到屏幕上
startX = event.getX();
startTime = System.currentTimeMillis();
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
// 移动中
} else if (event.getAction() == MotionEvent.ACTION_UP) {
// 手指抬起
// 判断当前横坐标差,在一秒完成