編輯:關於Android編程
效果如圖中藍框所框
<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+PC9wPgo8cHJlIGNsYXNzPQ=="brush:java;">import android.content.Context;
import android.content.res.TypedArray;
import android.text.InputType;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
public class ImageTextView extends LinearLayout {
private int width = 0;
private String textLabel = "";
private String textHintLabel = "";
private int image_id = 0;
private String edttext_inputtype = "";
private int label_width = 0;
private EditText editText = null;
private boolean isReadOnly = true;
private String defaultText = "";
private TextView txtView = null;
private ImageView img = null;
public ImageTextView(Context context){
super(context);
this.init(context);
}
public ImageTextView(Context context, AttributeSet attrs){
super(context, attrs);
TypedArray typedArray=context.obtainStyledAttributes(attrs, R.styleable.SelfImageTextAttr);
textLabel = typedArray.getString(R.styleable.SelfImageTextAttr_text_label);
textHintLabel = typedArray.getString(R.styleable.SelfImageTextAttr_text_hint_label);
image_id = typedArray.getResourceId(R.styleable.SelfImageTextAttr_image_id, 0);
edttext_inputtype = typedArray.getString(R.styleable.SelfImageTextAttr_edttext_inputtype);
label_width = Math.round(typedArray.getDimension(R.styleable.SelfImageTextAttr_label_width, 0));
defaultText = typedArray.getString(R.styleable.SelfImageTextAttr_default_text);
String txtReadOnly = typedArray.getString(R.styleable.SelfImageTextAttr_text_readonly);
if(txtReadOnly!=null&&txtReadOnly.equals("true")){//comment by danielinbiti
isReadOnly = false;
}
this.init(context);
}
public ImageTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.init(context);
// TODO Auto-generated constructor stub
}
public void setTextLabel(String textLabel) {
this.textLabel = textLabel;
txtView.setText(textLabel);
}
public void setTextHintLabel(String textHintLabel) {
this.textHintLabel = textHintLabel;
editText.setHint(textHintLabel);
}
public void setImage_id(int image_id) {
this.image_id = image_id;
img.setBackgroundResource(image_id);
}
public void setEdttext_inputtype(String edttext_inputtype) {
this.edttext_inputtype = edttext_inputtype;
int inputType = getType();
if(inputType!=-999){
editText.setInputType(inputType);
}
}
public void setLabel_width(int label_width) {
this.label_width = label_width;
txtView.setWidth(label_width);
}
public void setReadOnly(boolean isReadOnly) {
this.isReadOnly = !isReadOnly;
editText.setEnabled(!isReadOnly);
}
public void setDefaultText(String defaultText) {
this.defaultText = defaultText;
editText.setText(defaultText);
}
private int getType(){
if(edttext_inputtype!=null&&edttext_inputtype.trim().length()>0){
if(edttext_inputtype.equals("textPassword")){
return InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
}else if(edttext_inputtype.equals("textPhonetic")){
return InputType.TYPE_CLASS_PHONE | InputType.TYPE_TEXT_VARIATION_PHONETIC;
}else if(edttext_inputtype.equals("textEmailAddress")){
return InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
}
}
//return InputType.TYPE_CLASS_TEXT | InputType.TYPE_NULL;
return -999;
}
private void init(Context context){
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.image_text, null);
//this.setOrientation(LinearLayout.HORIZONTAL);
//this.setLayoutParams(new LinearLayout.LayoutParams(width,LayoutParams.WRAP_CONTENT));
txtView = (TextView)view.findViewById(R.id.imgLabel);
editText = (EditText)view.findViewById(R.id.imgEdtText);
img = (ImageView)view.findViewById(R.id.img);
if(image_id!=0){
img.setBackgroundResource(image_id);
}
txtView.setText(textLabel);
if(label_width!=0){
txtView.setWidth(label_width);
}
editText.setHint(textHintLabel);
int inputType = getType();
if(inputType!=-999){
editText.setInputType(inputType);
}
if(defaultText!=null&&defaultText.trim().length()>0){
editText.setText(defaultText);
}
editText.setEnabled(isReadOnly);
//editText.setEnabled(enabled);
this.addView(view,new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
}
public String getText(){
return editText.getText().toString();
}
public void setText(String txt){
this.editText.setText(txt);
}
public EditText getEditText(){
return editText;
}
}
在layout文件中的使用方式
之前寫過一篇Eclipse制作.so的文章,使用的是GNUstep模擬Linux環境,過程現在看來是想相當麻煩,後來發現一個簡單的方法就是通過項目右鍵添加Native S
Android提供了常見的音頻、視頻的編碼、解碼機制。借助於多媒體類MediaPlayer的支持,開發人員可以很方便在在應用中播放音頻、視頻。本篇博客主要講解在An
Android圓形圖片控件效果圖如下: 代碼如下: RoundImageView.java package com.dxd.roundimageview; imp
一、為什麼Android要進行分辨率與屏幕適配最大的原因是碎片化,因為Android的開源措施和各個廠商的自己細微修改,結果就變成了這個樣需要適配的屏幕尺寸就有這麼多:這