在下面的代码片段,我怎么能拿mClickable是相同的高度mTextArea?复合控制按钮大小以适应内部的EditText
public class EditSpinner extends LinearLayout {
EditText mTextArea;
ImageButton mClickable;
public EditSpinner(Context context, String[] options) {
super(context);
setOrientation(HORIZONTAL);
setGravity(Gravity.CENTER_VERTICAL);
setBackgroundResource(android.R.drawable.edit_text);
setAddStatesFromChildren(true);
setPadding(0, 0, 0, 0);
mTextArea = new EditText(context);
mTextArea.setSingleLine(true);
mTextArea.setBackgroundResource(0);
addView(mTextArea, new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f));
mClickable = new ImageButton(context);
mClickable.setBackgroundResource(0);
mClickable.setImageDrawable(
context.getResources().getDrawable(
android.R.drawable.btn_default_small));
//Scale to mTextArea.getHeight()... except getHeight doesn't work
addView(mClickable,
new LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
}
}
这个问题措手不及,希望编辑能够消除混淆。我只希望按钮的高度与edittext相同。 – 2011-04-06 17:26:19
我接受了答案,但如果你看到这个,我不知道如何使用重量来匹配尺寸? – 2011-04-06 21:40:48
发表了一个使用XML的例子。 – user432209 2011-04-07 00:54:10