Textview, textview

Source: Internet
Author: User

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




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.