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

What are the little experiences of Android development?

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

Share

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

This article will explain in detail what are the little experiences about Android development, and the content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

1. The return value of getTextSize in TextView is in px.

SetTextSize () is in units of sp.

So if you set it directly with the returned value, it will go wrong, and the solution is

In another form of setTextSize (), you can specify units:

SetTextSize (int unit, int size) TypedValue.COMPLEX_UNIT_PX: Pixels TypedValue.COMPLEX_UNIT_SP: Scaled Pixels TypedValue.COMPLEX_UNIT_DIP: Device Independent Pixels

two。 When inheriting from View, when drawing bitmap, you need to put the picture into the newly created drawable-xdpi

Otherwise, it is easy to change the drawing size.

3. Underline the text: textView.getPaint (). SetFlags (Paint.STRIKE_THRU_TEXT_FLAG)

4. ScrollView inherits from frameLayout, so you need to use frameLayout when using LayoutParams

5. Several ways of network programming in Android:

(1) Socket and ServerSocket for TCP/IP

(2) DatagramSocket and DatagramPackage for UDP. It should be noted here that considering that Android devices are usually handheld terminals, IP is allocated with the Internet. It's not fixed. Therefore, development is also a little different from ordinary Internet applications.

(3) HttpURLConnection for direct URL

(4) Google integrates Apache HTTP client, and HTTP can be used for network programming. Appache Http core and httpclient 4 versions are integrated for HTTP,Google, so pay special attention to Android does not support httpclient 3.x series, and currently does not support Multipart (MIME), you need to add your own httpmime.jar

(5) use Web Service. Android can support Xmlrpc and Jsonrpc through open source packages such as jackson, and you can also use Ksoap2 to implement Webservice

(6) display the web page directly using the WebView view component. Based on WebView development, Google has provided a chrome-lite-based Web browser, which can browse the web directly.

6. TranslateAnimation (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)

This is one of our most commonly used construction methods.

Float fromXDelta: this parameter indicates the difference between the starting point of the animation and the current View X coordinates

Float toXDelta, this parameter represents the difference between the end point of the animation and the current View X coordinates

Float fromYDelta, this parameter indicates the difference between the starting point of the animation and the current View Y coordinates

Float toYDelta) this parameter indicates the difference between the starting point of the animation and the current View Y coordinates.

If view is at point A (x+fromXDelta y), then the animation is moved from point B (point B, y+fromYDelta) to point C (point X, Delta).

7.android provides several ways to access UI threads in other threads.

Activity.runOnUiThread (Runnable)

View.post (Runnable)

View.postDelayed (Runnable, long)

Hanlder

AsyncTask (recommended)

Get a web page from the Internet and display its source code in a TextView package org.unique.async; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.util.ArrayList; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import android.app.Activity Import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; public class NetworkActivity extends Activity {private TextView message; private Button open; private EditText url @ Override public void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.network); message= (TextView) findViewById (R.id.message); url= (EditText) findViewById (R.id.url); open= (Button) findViewById (R.id.open) Open.setOnClickListener (new View.OnClickListener () {public void onClick (View arg0) {connect ();}});} private void connect () {PageTask task = new PageTask (this); task.execute (url.getText (). ToString ()) } class PageTask extends AsyncTask {/ / variable length input parameter, corresponding to AsyncTask.exucute (), ProgressDialog pdialog; public PageTask (Context context) {pdialog = new ProgressDialog (context, 0) Pdialog.setButton ("cancel", new DialogInterface.OnClickListener () {public void onClick (DialogInterface dialog, int I) {dialog.cancel ();}}); pdialog.setOnCancelListener (new DialogInterface.OnCancelListener () {public void onCancel (DialogInterface dialog) {finish ()) ); pdialog.setCancelable (true); pdialog.setMax (100); pdialog.setProgressStyle (ProgressDialog.STYLE_HORIZONTAL); pdialog.show ();} @ Override protected String doInBackground (String...) Params) {try {HttpClient client = new DefaultHttpClient (); / / params [0] represents the connected url HttpGet get = new HttpGet (params [0]); HttpResponse response = client.execute (get); HttpEntity entity = response.getEntity (); long length = entity.getContentLength () InputStream is = entity.getContent (); String s = null; if (is! = null) {ByteArrayOutputStream baos = new ByteArrayOutputStream (); byte [] buf = new byte [128]; int ch =-1; int count = 0 While ((ch = is.read (buf))! =-1) {baos.write (buf, 0, ch); count + = ch If (length > 0) {/ / if you know the length of the response, call publishProgress () update progress publishProgress ((int) ((count / (float) length) * 100) } / / Let the thread sleep 100ms Thread.sleep (100);} s = new String (baos.toByteArray ());} / / return the result return s } catch (Exception e) {e.printStackTrace ();} return null;} @ Override protected void onCancelled () {super.onCancelled () } @ Override protected void onPostExecute (String result) {/ / returns the content of the HTML page message.setText (result); pdialog.dismiss () } @ Override protected void onPreExecute () {/ / Task starts, you can display a dialog here, where you simply deal with message.setText (R.string.task_started);} @ Override protected void onProgressUpdate (Integer...) Values) {/ / Update progress System.out.println ("" + values [0]); message.setText ("" + values [0]); pdialog.setProgress (values [0]);}

Solutions that 8.Spinner cannot be used in dialog and tabhost

9. Eclipse associated JDK source code

(1)。 Click "window"-> "Preferences"-> "Java"-> "Installed JRES"

(2)。 To the right of "Installed JRES" is the list pane, which lists the JRE environment in the system. Select your JRE, then click "Edit..." on the edge, and an Edit JRE will appear.

(3)。 Select this item in the rt.jar file: "c:\ program files\ java\ jre_1.5.0_06\ lib\ rt.jar" click the "+" sign to the left to expand it.

(4)。 After expanding, you can see "Source Attachment: (none)", click this item, click the button "Source Attachment..." on the right, and select the "src.zip" file in your JDK directory.

10.Unable to open sync connection!

Restart the USB debugging in the settings

11.EditText setting cursor position problem

When you have some preset text in EditText, you want to set the cursor to the front. At first, you use setSelection (0), only to find that there is a problem with the Samsung P1000. After research, it is found that we need to call EditText.requestFocus () first, and then call setSelection (0). Otherwise, there will be a problem on the 2.x machine, but the 3.x is fine.

The home key in 12.Android is reserved by the system, so you can't use onKeyDown like listening back key, but you can add your own handling code according to some events of activity and view that will be triggered when you press the home key. Some people on the Internet say that you can use onAttachWindow to intercept the Home button, but you haven't tried.

13. When rendering with surfaceView, if you want to have other View in it when needed, you can put surfaceView and other View in layout, and you can hide other view normally.

14. Using android:imeOptinos, you can make some interface settings for the soft keyboard that comes with Android:

Android:imeOptions= "flagNoExtractUi" / / makes the soft keyboard not full screen display At the same time, this property can also control the display content of the button in the lower right corner of the soft keyboard. By default, it is the enter key android:imeOptions= "actionNone" / / the right side of the input box does not have any prompt android:imeOptions= "actionGo" / / the button in the lower right corner is' start 'android:imeOptions= "actionSearch" / / the button in the lower right corner is a magnifying glass picture Search for android:imeOptions= "actionSend" / / the button content in the lower right corner is' send 'android:imeOptions= "actionNext" / / the button content in the lower right corner is' next 'android:imeOptions= "actionDone" / / the button content in the lower right corner is' done'

15. Add shadows to TextView

2dip 2dip # ffffff 12sp # 00ff00 5 3 6

16. How to set the Chinese in TextView to bold?

Use android:textStyle= "bold" in xml files to set English to bold, but not Chinese to bold. The way to set Chinese to bold is:

TextView tv = (TextView) findViewById (R.id.TextView01)

TextPaint tp = tv.getPaint ()

Tp.setFakeBoldText (true)

What is the small experience of Android development to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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