评级界面
<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"
>
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:rating="3"
android:numStars="5"
android:stepSize="0.5"
android:id="@+id/star"/>
<!-- rating="3"默认3 numStars="5"总数5 stepSize="0.5"最小单位半个-->
</RelativeLayout>
点击事件
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
<TextSwitcher
android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TextSwitcher>
图片切换
<ImageSwitcher
android:id="@+id/switcher"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ImageSwitcher>
//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) {
// 手指抬起
// 判断当前横坐标差,在一秒完成動作,並且滑行距離大於50
if (System.currentTimeMillis() - startTime < 1000) {
if (startX - event.getX() >= 50) {
// 向左滑的差,即下一页
if (index < allImgs.length - 1) {
index++;
// 进入的动画是滑动的 public TranslateAnimation
// (float fromXDelta, float toXDelta, float
// fromYDelta, float toYDelta)
Animation inAnim = new TranslateAnimation(
Globals.SCREEN_WIDTH + 10, 0, 0, 0);
Animation outAnim = new TranslateAnimation(
0, -Globals.SCREEN_WIDTH - 10, 0, 0);
// 设置动画持续时间
inAnim.setDuration(1000);
outAnim.setDuration(1000);
switcher.setInAnimation(inAnim);
switcher.setOutAnimation(outAnim);
switcher.setImageResource(allImgs[index]);
}
} else if (event.getX() - startX >= 50) {
// 上一页
if (index > 0) {
index--;
Animation inAnim = new TranslateAnimation(
-Globals.SCREEN_WIDTH - 10, 0, 0, 0);
Animation outAnim = new TranslateAnimation(
0, Globals.SCREEN_WIDTH + 10, 0, 0);
// 设置动画持续时间
inAnim.setDuration(1000);
outAnim.setDuration(1000);
switcher.setInAnimation(inAnim);
switcher.setOutAnimation(outAnim);
switcher.setImageResource(allImgs[index]);
}
}
}
}
} else {
Toast.makeText(MainActivity.this, "支持单点操作",
Toast.LENGTH_SHORT).show();
}
return false;
}
});
contentresolver扫描sdcard查找视频资源
// 根据一个唯一的标识,来调用某些数据库操作.
Cursor c1 = resolver.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
null, null, null, null);
if (c1.moveToFirst()) {
while (!c1.isAfterLast()) {
String album = c1.getString(c1.getColumnIndex(Video.Media.ALBUM));
String artist = c1.getString(c1.getColumnIndex(Video.Media.ARTIST));
String fileName = c1.getString(c1.getColumnIndex(Video.Media.DISPLAY_NAME));
String name = c1.getString(c1.getColumnIndex(Video.Media.TITLE));
String duration = c.getString(c1.getColumnIndex(Video.Media.DURATION));
String path = c1.getString(c1.getColumnIndex(Video.Media.DATA));//路径
MediaPlayer player = new MediaPlayer();
System.out.println(album + " --> " + artist + " --> " + name
+ " --> " + duration + " --> " + path + " --> "
+ fileName);
c1.moveToNext();
}
}
c1.close();