Some of the properties of Android learning TextView are explained

Source: Internet
Author: User

Delia

Ways to dynamically change controls


1. Declaring a control parameter gets an object

Linearlayout.layoutparams linear = (Layoutparams) view.getlayoutparams ();

2. Set the control parameters, such as width:

Linear.width = 10;

3. Make the settings effective

View.setlayoutparams (linear);

Note: The view represents the corresponding control object

Posted @ 2012-03-01 11:29 Delia Read (5) Comments (0) Edit

Let TextView bring its own scroll bar


There is a Ellipsize property in TextView that shows how the control is displayed when the text is too long, as explained below:

1.android:ellipsize= "Start"-the ellipsis appears at the beginning

2.android:ellipsize= "End"--ellipsis appears at the end

3.android:ellipsize= "Middle"--ellipsis displayed in the middle

4.android:ellipsize= "Marquee" – Display in the form of a marquee (animated lateral movement)

Text scrolls around three properties:

Android:singleline= "true"

Android:ellipsize= "Marquee"

android:marqueerepeatlimit= "Marquee_forever"

Android in order to achieve text scrolling can be embedded in the scrollview of a textview, in fact, TextView can also implement multi-line scrolling, after all, ScrollView must only have a direct sub-class layout. Simply setting a few properties in layout can be easily implemented.

<textview

Android:id= "@+id/tvcwj"

Android:layout_width= "Fill_parent"

android:layout_height= "Wrap_content"

android:scrollbars= "Vertical" <!– vertical scroll bar –>

Android:singleline= "False" <!– implements multiple lines –>

Android:maxlines= "15″<!– up to 15 lines –>

Android:textcolor= "#FF0000 ″

/>

< TextView

Android:id = "@+id/app_shortcontent"

Android:layout_width = "Wrap_content"

Android:layout_height = "Wrap_content"

Android:singleline = "true"

Android:textcolor = "#FFFFFFFF"

android:scrollhorizontally = "true"

android:focusable = "true"

Android:ellipsize = "Marquee"

Android:marqueerepeatlimit = "Marquee_forever"/>

Of course, in order for TextView to move, we also need to use the TextView Setmovementmethod method to set up a scrolling instance, the code is as follows

TextView TV = (TextView) Findviewbyid (R.ID.TVCWJ);

Tv.setmovementmethod (Scrollingmovementmethod.getinstance ()); Android Development Network hint related can view SDK in Android.text.method branch Learn more

Report:

By the way, the implementation of TextView automatic scrolling, two methods are described below:

First, in the code to implement:

TextView. Setellipsize (TextUtils.TruncateAt.MARQUEE);

TextView. Setsingleline (True);

TextView. Setmarqueerepeatlimit (6);

Second, in the XML implementation:

<textview android:id= "@+id/textview01″android:layout_width=" Wrap_content "

android:layout_height= "Wrap_content" android:singleline= "true"

android:text= "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"

android:marqueerepeatlimit= "Marquee_forever" android:ellipsize= "marquee"

Android:scrollhorizontally= "true" android:width= "150dip" ></TextView>

All OK, when TextView gets the focus, it scrolls automatically.

Supplemental ==============================

Whether manually or automatically you need to implement scrolling to add ScrollView

The handle can then be used to invoke ScrollView's Scrollto method for scrolling

Handler Mhandler = new Handler ();

Private Runnable Mscrolltobottom = new Runnable () {

public void Run () {

Mscrollview.scrollto (0, offset);

}

};

Ontouch inside

Mhandler.post (Mscrolltobottom);

Supplemental ====================

Add:

1, set the ellipsize of TextView to marquee (said above)

2. Set the deprecated single line to True

3, set TextView Marquee repeat limit property (scroll back number, default is countless back)

Put a code on it.

Textview.setellipsize (TextUtils.TruncateAt.MARQUEE);

Textview.setsingleline (TRUE);

Textview.setmarqueerepeatlimit (6);

Some of the properties of Android learning TextView are explained

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.