In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to use Android to achieve text elimination effect". In daily operation, I believe many people have doubts about how to use Android to achieve text elimination effect. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to use Android to achieve text elimination effect". Next, please follow the editor to study!
Take a look at the effect picture first:
Because the project is related to speech recognition, sometimes invalid audio inadvertently communicated by people will be recognized and displayed on the interface. In order to be beautiful, the customer asked us to clear these invalid recognition text with a right-to-left animation, so there is the following technical implementation.
Well, after the effect is done, I find that the principle is very simple, just for this record.
1. Paste the layout file here first.
Btn_click1 is designed for demonstration convenience, but it is not taken into account. Note that TextView requires:
Android:ellipsize= "none" android:singleLine= "true"
Two attributes, and the effect is only for one line of text.
2. Paste the java code
Public class MainActivity extends AppCompatActivity {private TextView textView; private Button btn_click; private Button btn_click1; private Handler mHandler; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); mHandler = new Handler (); textView = findViewById (R.id.tv_text); btn_click = findViewById (R.id.btn_click) Btn_click1 = findViewById (R.id.btn_click1); btn_click.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {showAsrAnim ();}}) Btn_click1.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {textView.setVisibility (View.VISIBLE); textView.setText) ;}) } private void showAsrAnim () {mHandler.post (new Runnable () {@ Override public void run () {/ / here we use ValueAnimator.ofInt to create an animation with a value from the width of textView to 2, and the animation duration is 400ms Then let the animation begin / / the first step: create a ValueAnimator instance ValueAnimator animator = ValueAnimator.ofInt (textView.getWidth (), 2) Animator.setInterpolator (new LinearInterpolator ()); animator.setDuration (4000) / / step 2: add listening animator.addUpdateListener (new ValueAnimator.AnimatorUpdateListener () {@ Override public void onAnimationUpdate (ValueAnimator animation) {/ / get the value of the current motion point int width = (int) animation.getAnimatedValue () when ValueAnimator is in motion ChangeLayout (width); if (width = = 2) {textView.setText (""); textView.setVisibility (View.INVISIBLE); ViewGroup.LayoutParams params = textView.getLayoutParams () Params.width = ViewGroup.LayoutParams.WRAP_CONTENT; textView.setLayoutParams (params);}); animator.start ();}}) } private void changeLayout (int width) {ViewGroup.LayoutParams params = textView.getLayoutParams (); params.width = width; textView.setLayoutParams (params);}
There are comments in the code, create an instance of ValueAnimator, add listeners, change the width of the TextView through motion, and set the text to be empty and invisible when the minimum width 2dp is reached.
At this point, the study on "how to use Android to achieve text elimination effect" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.