編輯:關於Android編程
項目過程中可能會用到可以折疊和展開的TextView , 這裡給出一種實現思路,自定義控件。
package com.example.expandtextviewdemo; import android.content.Context; import android.content.res.TypedArray; import android.text.SpannableStringBuilder; import android.util.AttributeSet; import android.view.View; import android.widget.TextView; public class ExpandableTextView extends TextView { private static final int DEFAULT_TRIM_LENGTH = 200; private static final String ELLIPSIS = "....."; private CharSequence originalText; private CharSequence trimmedText; private BufferType bufferType; private boolean trim = true; private int trimLength; public ExpandableTextView(Context context) { this(context, null); } public ExpandableTextView(Context context, AttributeSet attrs) { super(context, attrs); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ExpandableTextView); this.trimLength = typedArray.getInt(R.styleable.ExpandableTextView_trimLength, DEFAULT_TRIM_LENGTH); typedArray.recycle(); setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { trim = !trim; setText(); requestFocusFromTouch(); } }); } private void setText() { super.setText(getDisplayableText(), bufferType); } private CharSequence getDisplayableText() { return trim ? trimmedText : originalText; } @Override public void setText(CharSequence text, BufferType type) { originalText = text; trimmedText = getTrimmedText(text); bufferType = type; setText(); } private CharSequence getTrimmedText(CharSequence text) { if (originalText != null && originalText.length() > trimLength) { return new SpannableStringBuilder(originalText, 0, trimLength + 1).append(ELLIPSIS); } else { return originalText; } } public CharSequence getOriginalText() { return originalText; } public void setTrimLength(int trimLength) { this.trimLength = trimLength; trimmedText = getTrimmedText(originalText); setText(); } public int getTrimLength() { return trimLength; } }
package com.example.expandtextviewdemo; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class ExpandableTextActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_expandable_text); String yourText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " + "Ut volutpat interdum interdum. Nulla laoreet lacus diam, vitae " + "sodales sapien commodo faucibus. Vestibulum et feugiat enim. Donec " + "semper mi et euismod tempor. Sed sodales eleifend mi id varius. Nam " + "et ornare enim, sit amet gravida sapien. Quisque gravida et enim vel " + "volutpat. Vivamus egestas ut felis a blandit. Vivamus fringilla " + "dignissim mollis. Maecenas imperdiet interdum hendrerit. Aliquam" + " dictum hendrerit ultrices. Ut vitae vestibulum dolor. Donec auctor ante" + " eget libero molestie porta. Nam tempor fringilla ultricies. Nam sem " + "lectus, feugiat eget ullamcorper vitae, ornare et sem. Fusce dapibus ipsum" + " sed laoreet suscipit. "; ExpandableTextView expandableTextView = (ExpandableTextView) findViewById(R.id.lorem_ipsum); expandableTextView.setText(yourText); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.expandable_text, menu); return true; } }
Android中登錄界面的記住密碼功能實現,將用戶輸入的賬號和密碼以SharedPreferences方式存儲(注意的是,密碼要用MD5明文加密)。 界面xml
如今,大部分的AR都是基於移動設備的,所以這裡我們嘗試在Android中調用OpenCV的功能來做一些相關的測試。由於OpenCV是基於C語言和部分C++語言開發的,而A
本篇我們准備為地圖添加:第一,定位功能;第二,與方向傳感器結合,通過旋轉手機進行道路的方向確認。有了這兩個功能,地圖已經可以為我服務了@一啟動就自動定位了a,MainAc
Android啟動過程中的第一個進程init,在啟動過程中會啟動兩個關鍵的系統服務進程ServiceManager和Zygote。本文要介紹的就是Zygote進程的啟動,