展会信息港展会大全

android组件:评级组件;textswither的text用.FrameLayout.LayoutParams,触屏监听;
来源:互联网   发布日期:2015-10-13 15:15:07   浏览:1062次  

导读:评级界面 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:ste...

评级界面

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) {

// 手指抬起

// 判断当前横坐标差,在一秒完成

赞助本站

人工智能实验室

相关热词: android开发

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港