Use of the textview control and obtaining the screen resolution

Source: Internet
Author: User


Textview is a basic control in Android. It inherits from the view. Other controls, such as button, digitalclock, and edittext, are expanded by textview.


For more information (inherited from textview), see the android development documentation, for example:

 

The textview control inherits from the view and implements the onpredrawlistener interface.


Directly inherited from the texview control include: button, checkedtextview, digitalclock, and so on.


Indirectly inherited from textview include checkbox, radiobutton, togglebutton, and so on.

The properties of the controls in android can be set directly on the main control page or in the style. The following is an example of the settings:

    <TextView        android:id="@+id/tvShowInfo"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentLeft="true"        android:layout_alignParentTop="true"        android:layout_marginLeft="98dp"        android:layout_marginTop="203dp"        android:text="abc"        android:textSize="24dp"        android:textColor="#DBDB70">            </TextView>

I set the font size and color of textview text above. This can also be set through the style attribute:

<resources xmlns:android="http://schemas.android.com/apk/res/android">    <style name="AppTheme" parent="android:Theme.Light"/><item name="android:textColor">#DBDB70</item><item name="android:textSize">30dp</item></resources>

Then, add the style to the control page:

    <TextView        android:id="@+id/tvShowInfo"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentLeft="true"        android:layout_alignParentTop="true"        android:layout_marginLeft="98dp"        android:layout_marginTop="203dp"        android:text="come on"        style="@style/AppTheme">            </TextView>

The following shows how to obtain the resolution of the android simulator and go to the code editing page:

// Set the style to the window to setcontentview (R. layout. activity_main); // Step 1: Find the control textview TV = (textview) findviewbyid (R. id. tvshowinfo); // the screen resolution displaymetrics dm = new displaymetrics (); getwindow (). getwindowmanager (). getdefadisplay display (). getmetrics (DM); int W = DM. widthpixels; // int H of the screen width = DM. heightpixels; // high screen TV. settext ("high:" + W + "width:" + H); // set it to the control.


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.