Textview, textview
When textview is set to some attributes, it can be converted into a lawn lamp. But if the character length is not long enough .... You will find that the settings are ineffective. Therefore, I have been using google for a long time, and I have finally found several solutions that suit me. In my summary. It is still a good programmer in foreign countries. Domestic searches are all articles on a thousand times!
1,
<LinearLayout android:id="@+id/ticker_area" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > </LinearLayout>
public void setticker(String text, Context contx) { if (text != "") { LinearLayout parent_layout = (LinearLayout) ((Activity) contx) .findViewById(R.id.ticker_area); TextView view = new TextView(contx); view.setText(text); view.setTextColor(Color.RED); view.setTextSize(15.0F); Context context = view.getContext(); // gets the context of the view // measures the unconstrained size of the view // before it is drawn in the layout view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); // takes the unconstrained width of the view float width = view.getMeasuredWidth(); float height = view.getMeasuredHeight(); // gets the screen width float screenWidth = ((Activity) context).getWindowManager() .getDefaultDisplay().getWidth(); view.setLayoutParams(new LinearLayout.LayoutParams((int) width, (int) height, 1f)); System.out.println("width and screenwidth are" + width + "/" + screenWidth + "///" + view.getMeasuredWidth()); // performs the calculation float toXDelta = width - (screenWidth - 0); // sets toXDelta to -300 if the text width is smaller that the // screen size if (toXDelta < 0) { toXDelta = 0 - screenWidth;// -300; } else { toXDelta = 0 - screenWidth - toXDelta;// -300 - toXDelta; } // Animation parameters Animation mAnimation = new TranslateAnimation(screenWidth, toXDelta, 0, 0); mAnimation.setDuration(15000); mAnimation.setRepeatMode(Animation.RESTART); mAnimation.setRepeatCount(Animation.INFINITE); view.setAnimation(mAnimation); parent_layout.addView(view); } }
Call:
Setticker ("latest message", context );
2,
webView = (WebView)findViewById(R.id.web); String summary = "
3. This is what I have come up with. It is an animation, similar to the first one,
Translate_scroll.xml.
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="10000" android:fromXDelta="-100%p" android:interpolator="@android:anim/anticipate_interpolator" android:toXDelta="100%p" />
Call:
Animation animation = AnimationUtils.loadAnimation(this.currentlyAssociatedActivity, R.anim.translate_scroll); animation.setRepeatMode(Animation.RESTART); animation.setRepeatCount(Animation.INFINITE); titleView.setAnimation(animation);