Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Android 2.1s

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use Android 2.1, has a certain reference value, interested friends can refer to, I hope you have a lot of gains after reading this article, let Xiaobian take you to understand.

1. environment construction

Ubuntu+eclipse+ADT

2. Android starts slowly?

There is no way, it is really slow, wait, the general saying is to start *** times after not closing, after the deployment is much faster, after testing, it is indeed faster. The most unacceptable thing is that even clicking the Home button is very slow.

3.R.layout.main cannot be resolved

Just wrote a line out of such an error, let me have no temper to find out why.

Solution:

(1) Delete "import android.R" in the third line. Note: I don't know when it was added.

Check Eclipse's "Project->Build Automatically" box.

Cause analysis:

(1) After deleting "import andorid R", the project is automatically generated from the/res folder. Oh, I have to parse it in the meantime, otherwise it will find it from the Android resource class.

Using Eclipse for Java development, the first thing to notice is that its compilation is intelligent, go to Preferences and enable dynamic build (workbench>Build automatically). This way, Eclipse automatically compiles the document and files that depend on it each time we save the file. So when we want to run the app, it's basically saved and *** version. This can save time when dealing with large code volumes.

4. about layout

The book I bought is based on the previous version (Android SDK 1.0r2). The layout of the controls is still android:layout_x="61px". Now I have to write android:layout_marginLeft="61px", otherwise it won't work. Curious is that it must also be px value, otherwise the compiler will report an error, the compiler can also recognize the contents of the string! It was indeed powerful.

5. To display URLs in TextView you need to add android:autoLink = "all" to the TextView node

6. Constants (res\values) This folder defines all the constants to be used in the project. It is a good habit to program in advance. For example:

(1) Define color constants (color.xml)

#808080FF #FFFFFFFF

(2)Define string constants (strings.xml)

Hello World Android Test Android account password

Well defined how to use it, there are two ways to quote:

(1) Tag reference: android:text="@string/str_id"

(2) Code references:

Resources resources = getBaseContenxt().getResources(); Drawable HippoDrawable = resources.getDrawable(R.drawable.white); //String aa = resources.getString(R.string.app_name); //String bb = getString(R.string.app_name); TextView tv= (TextView)findViewByID(R.id.text); tv.setBackground(HippoDrawable); //you can use graphics.Color, the default color for android, but there are only 12 common colors /× Color.BLACK Color.BLUE Color.CYAN Color.DKGRAY Color.GRAY Color.GREEN Color.LIGRAY Color.MAGENTA Color.REN Color.TRANSPARENT Color.WHITE Color.YELLOW ×/view sourceprint? 1 7. Get the resolution of your phone view sourceprint? 1 This is the difference between Android and ios, this system is used by different mobile phone manufacturers, the size of the machine is also different, and Apple's system is only used by himself, so it can be unified. view sourceprint? 1 DisplayMetrice dm = new DisplayMetrice(); getWindowManager().getDefaultDisplay().getMetrice(dm); string strOpt="The resolution of the phone is: "dm.widthPixels + " x " + dm.heightPixels;

7. Definition of Style

Always have to specify the size of the text one by one, color is not the way ah, so there are similar CSS styles to appear. The stylesheet file is named style.xml and placed at res/values/style.xml

Examples of defining styles:

view sourceprint? 01 18sp

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report