Android 如何在同一活动中使用ViewFlipper(或)ViewSwitcher和TextSwitcher。。?
我是android开发的初学者。我能够实现textSwitcher和ViewSwitcher,但在活动中是单独实现的。我希望他们在同一活动中发挥作用 这段代码在IDE中没有给出错误,但在模拟器中给出了它的“强制关闭” 导入后的代码以及所有Android 如何在同一活动中使用ViewFlipper(或)ViewSwitcher和TextSwitcher。。?,android,android-layout,android-widget,android-view,Android,Android Layout,Android Widget,Android View,我是android开发的初学者。我能够实现textSwitcher和ViewSwitcher,但在活动中是单独实现的。我希望他们在同一活动中发挥作用 这段代码在IDE中没有给出错误,但在模拟器中给出了它的“强制关闭” 导入后的代码以及所有 ViewFlipper vS1,vS2,vS3; Button onep,twop,lose,win,help,settings,start,pick1,pick2; int condn,total,max=5,min=1,rem; TextSwitcher
ViewFlipper vS1,vS2,vS3;
Button onep,twop,lose,win,help,settings,start,pick1,pick2;
int condn,total,max=5,min=1,rem;
TextSwitcher minte,maxte,select1,select2,coinsrem;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Animations
Animation in = AnimationUtils.loadAnimation(this,
android.R.anim.slide_in_left);
Animation out = AnimationUtils.loadAnimation(this,
android.R.anim.slide_out_right);
// Text Views ----
minte.findViewById(R.id.min);
maxte.findViewById(R.id.max);
minte.setFactory(new TextSwitcherFactory());
maxte.setFactory(new TextSwitcherFactory());
minte.setText("Hello");
// switching Views ----
vS1 =(ViewFlipper) findViewById(R.id.vs1);
vS2 =(ViewFlipper) findViewById(R.id.vs2);
vS3 =(ViewFlipper) findViewById(R.id.vs3);
vS1.setInAnimation(in);
vS1.setOutAnimation(out);
vS2.setInAnimation(in);
vS2.setOutAnimation(out);
vS3.setInAnimation(in);
vS3.setOutAnimation(out);
// create RangeSeekBar as Integer range between 20 and 75
RangeSeekBar<Integer> seekBar = new RangeSeekBar<Integer>(20, 75, getBaseContext());
seekBar.setOnRangeSeekBarChangeListener(this);
// add RangeSeekBar to pre-defined layout
ViewGroup layout = (ViewGroup) findViewById(R.id.rangeseek);
layout.addView(seekBar);
//----buttons-------------------------
win = (Button)findViewById(R.id.win);
lose = (Button)findViewById(R.id.loses);
win.setOnClickListener(this);
lose.setOnClickListener(this);
//----buttons end----------------------
//---Animating the views---
}
@Override
public void rangeSeekBarValuesChanged(Integer minValue, Integer maxValue) {
// TODO Auto-generated method stub
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
case R.id.win:
condn = 1;
vS2.showNext();
break;
case R.id.loses :
condn =0;
vS2.showNext();
break;
}
}
public class TextSwitcherFactory implements ViewSwitcher.ViewFactory{
@Override
public View makeView() {
// TODO Auto-generated method stub
TextView t = new TextView(LastActivity.this);
t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
t.setTextSize(36);
t.setTextColor(Color.argb(255, 255, 204, 51));
return t; }
}
视图翻转器vS1、vS2、vS3;
按钮onep,twop,lose,win,help,settings,start,pick1,pick2;
内部条件,总计,最大值=5,最小值=1,rem;
文本切换器minte、maxte、select1、select2、coinsrem;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//动画
动画输入=AnimationUtils.loadAnimation(此,
android.R.anim.slide_in_left);
动画输出=AnimationUtils.loadAnimation(此,
android.R.anim.滑出(右);
//文本视图----
minte.findviewbyd(R.id.min);
maxte.findViewById(R.id.max);
setFactory(新的TextSwitcherFactory());
setFactory(新的TextSwitcherFactory());
minte.setText(“你好”);
//交换意见----
vS1=(ViewFlipper)findViewById(R.id.vS1);
vS2=(ViewFlipper)findViewById(R.id.vS2);
vS3=(ViewFlipper)findViewById(R.id.vS3);
vS1.设定无生气(in);
vS1.设置输出动画(输出);
vS2.设定无生气(in);
vS2.设置输出动画(输出);
vS3.设定无生气(in);
vS3.设置输出动画(输出);
//将RangeSekbar创建为介于20和75之间的整数范围
RangeSeekBar seekBar=新的RangeSekBar(20,75,getBaseContext());
seekBar.setonRangeSeekbarchaneListener(此);
//将RangeSekbar添加到预定义布局
视图组布局=(视图组)findViewById(R.id.rangeseek);
布局。添加视图(参见kbar);
//----钮扣-------------------------
win=(按钮)findViewById(R.id.win);
lose=(按钮)findViewById(R.id.loss);
win.setOnClickListener(这个);
lose.setOnClickListener(这个);
//----按钮端----------------------
//---设置视图的动画---
}
@凌驾
public void range seekbarvalueschanged(整数minValue,整数maxValue){
//TODO自动生成的方法存根
}
公共void onClick(视图v){
//TODO自动生成的方法存根
开关(v.getId())
{
案例R.id.win:
condn=1;
vS2.showNext();
打破
案件R.id.败诉:
condn=0;
vS2.showNext();
打破
}
}
公共类TextSwitcherFactory实现ViewSwitcher.ViewFactory{
@凌驾
公共视图makeView(){
//TODO自动生成的方法存根
TextView t=新的TextView(LastActivity.this);
t、 设置重力(重力.顶部|重力.中心|水平);
t、 尺寸(36);
t、 setTextColor(Color.argb(255、255、204、51));
返回t;}
}
没有道理
你应该像这样初始化它们:
minte =(TextSwitcher) findViewById(R.id.min);
从您的代码来看,您似乎正在尝试初始化3个独立的ViewFlipper并在它们之间切换。这不是怎么做的。ViewFlipper(或ViewSwitcher)是FrameLayout类的扩展。因此,它一次只显示一个子视图 要修复代码,请仅定义一个ViewFlipper。在该视图下,定义要在其中切换的3个视图(即RelativeLayout、LinearLayout等) 而且,看起来你也在尝试做一些动画。因此,您可能最终希望使用ViewAnimator类,它只是ViewFlipper的父类 谷歌搜索一些教程。外面有一些好的 我希望这有帮助
minte =(TextSwitcher) findViewById(R.id.min);