当前位置:网站首页>Function and usage of textswitch text switcher

Function and usage of textswitch text switcher

2022-07-07 17:36:00 XLMN

textSwitch Function and usage of text switcher
testswitch Inherited viewswitch, Therefore, possession and viewswitcher Same features , You can switch view Use animations for components ,
testswitcher and imageview Acquaintance requires a viewfactory, The difference is ,testswitcher need viewfactory Of makeview Return to one textview Components
public class MainActivity extends Activity {
TextSwitcher ts;
String[] str=new String[]{
“mia”,“love mia”,“miss mia”,“010802”
};
int curstr;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.textswitcher);
ts = (TextSwitcher) findViewById(R.id.textswitcher);
ts.setFactory(new ViewFactory() {

                    @Override
                    public View makeView() {
                            // TODO Auto-generated method stub
                            TextView tv=new TextView(MainActivity.this);
                            tv.setTextSize(40);
                            tv.setTextColor(Color.MAGENTA);
                            return tv;
                    }
            });
            next(null);
    }
    // Define processing functions , Controls the display of the next string 
    public void next(View source) {
            ts.setText(str[curstr++%str.length]);
    }

}

<?xml version="1.0" encoding="utf-8"?>

<!--  Define a testswitcher, And specify the animation effect when text switching  -->

<TextSwitcher
    android:id="@+id/textswitcher"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inAnimation="@android:anim/slide_in_left"
    android:onClick="next"
    android:outAnimation="@android:anim/slide_out_right" >
</TextSwitcher>

 Insert picture description here

原网站

版权声明
本文为[XLMN]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071527554010.html