setCompoundDrawablesとsetCompoundDrawablesWithIntrinsicBoundsの違い
テキストと画像の相対位置を手動で設定する場合、次の方法が一般的です.
setCompoundDrawables(left, top, right, bottom);
setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)
Drawableをtextの左、上、右、下に表示するように設定します.
(Textview、ButtonどちらでもOK)
しかし、両者にはいくつかの違いがあります.
setCompoundDrawablesが描いたdrawableの幅はdrawableである.setBound()設定の幅と高さ、
だからThe Drawables must already have had setBounds(Rect)called.
使う前にDrawableを使わなければならないという意味です.setBounds Drawableの長さと幅を設定します.
S t e C o m poundDrawablesWithIntrinsicBoundsはdrawableの幅を描いたものでdrawableで固定された幅の高さです
つまりgetIntrinsicWidth()とgetIntrinsicHeight()で得られるので、
The Drawables' bounds will be set to their intrinsic bounds.この言葉は!
setCompoundDrawables(left, top, right, bottom);
setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom)
Drawableをtextの左、上、右、下に表示するように設定します.
(Textview、ButtonどちらでもOK)
しかし、両者にはいくつかの違いがあります.
setCompoundDrawablesが描いたdrawableの幅はdrawableである.setBound()設定の幅と高さ、
だからThe Drawables must already have had setBounds(Rect)called.
使う前にDrawableを使わなければならないという意味です.setBounds Drawableの長さと幅を設定します.
S t e C o m poundDrawablesWithIntrinsicBoundsはdrawableの幅を描いたものでdrawableで固定された幅の高さです
つまりgetIntrinsicWidth()とgetIntrinsicHeight()で得られるので、
The Drawables' bounds will be set to their intrinsic bounds.この言葉は!
private AutoCompleteTextView mEditText;
mEditText = new AutoCompleteTextView(context,attrs);
mEditText.setHint(R.string.btn_search);
mEditText.setTextSize(14);
mEditText.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.iphonesearch_search_3), null, null, null);
mEditText.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {}
public void beforeTextChanged(CharSequence s, int start, int count,int after) {}
public void onTextChanged(CharSequence s, int start, int before,int count) {
// ゆ � boolean isSearch = false;
if (s == null || s.toString().equals("")) {
mClose.setVisibility(View.INVISIBLE);
isSearch = false;
} else {
mClose.setVisibility(View.VISIBLE);
isSearch = true;
}
mListener.startSearch(isSearch,s.toString());
}});
mEditText.setOnFocusChangeListener(new OnFocusChangeListener(){
public void onFocusChange(View v, boolean hasFocus) {
if (!firstFocusChange) {
firstFocusChange = true;
if (mListener != null) {
mListener.getFirstFocus();
}
Animation ca =new ScaleAnimation(1.0f,0.8f,1.0f,1.0f);
ca.setFillAfter(true);
ca.setDuration(300);
mBackground.startAnimation(ca);
}
}});
mEditText.setBackgroundColor(0);
mEditText.setMaxWidth(240);
mEditText.setMinWidth(240);
mEditText.setMaxLines(1);
mEditText.setMinLines(1);