列表视图中的 EditText 高度与行高不匹配
我有一个类似于我的列表视图适配器中使用的 CustomAdapter 示例的 veiw:
class FooView extends LinearLayout
{
EditText mInputBox;
public FooView(Context context)
{
this.setOrientation(HORIZONTAL);
this.setPadding(0,0,0,0);
mInputBox = new EditText(context);
// formatted to fit on screen
float dip =
TypedValue.applyDimension(
COMPLEX_UNIT_DIP,
48.0f,
getResources().getDisplayMetrics());
LayoutParams lp =
new LayoutParams(
LayoutParams.FILL_PARENT,
(int)Math.ceil(dip),
1.0f);
lp.setMargins(0,0,0,0);
addView(mInputBox, lp);
}
}
但每行中的 EditView 下方都有一个空格:
我扩展了 FooView 并在顶部案例中添加了一个 ImageButton(未添加在图片中)。在该视图中,ImageView 完美适合该行。
ImageButton b = new ImageButton(context);
b.setImageResource(R.drawable.foo);
b.setScaleType(ScaleType.CENTER_INSIDE); //also tried FIT_XY didnt notice a difference
addView(b, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
ImageButton 的尺寸为:
- ldpi: 32 x 32px
- mdpi: 48 x 48px (其中我得到 EditText 的 48)
- hdpi: 72 x 72px
- xhdpi: 96 x 96px
为什么我的 EditText 无法正确缩放?
I have a veiw similar to the CustomAdapter example that is used in my adapter for my listview:
class FooView extends LinearLayout
{
EditText mInputBox;
public FooView(Context context)
{
this.setOrientation(HORIZONTAL);
this.setPadding(0,0,0,0);
mInputBox = new EditText(context);
// formatted to fit on screen
float dip =
TypedValue.applyDimension(
COMPLEX_UNIT_DIP,
48.0f,
getResources().getDisplayMetrics());
LayoutParams lp =
new LayoutParams(
LayoutParams.FILL_PARENT,
(int)Math.ceil(dip),
1.0f);
lp.setMargins(0,0,0,0);
addView(mInputBox, lp);
}
}
and yet I have a space underneath the EditView in each row:
I extend FooView and add an ImageButton in the top case (not added in picture). In that view, the ImageView fits to the row perfectly.
ImageButton b = new ImageButton(context);
b.setImageResource(R.drawable.foo);
b.setScaleType(ScaleType.CENTER_INSIDE); //also tried FIT_XY didnt notice a difference
addView(b, new LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
The dimensions of the ImageButton are:
- ldpi: 32 x 32px
- mdpi: 48 x 48px (where i got the 48 for the EditText)
- hdpi: 72 x 72px
- xhdpi: 96 x 96px
why does my EditText not scale properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜您对 EditText 的背景图像有疑问。将背景显式设置为颜色或 XML 资源,然后查看情况是否会改变。
我还会看看 WRAP_CONTENT 是否有效,而不是固定的高度数字,如果可以,请尝试之后的选项。
如果这些都不起作用,请确保将自定义布局和 EditText 上的填充和边距设置为零。
基本上,这个想法是尝试这些事情,获得积极的结果,然后你可以一件一件地删除事情,看看真正带来改变的是什么。
I would guess you're having issues with the background image for the EditText. Explicitly set the background to a color or XML resource, and see if that changes the situation.
I'd also see if WRAP_CONTENT works instead of a fixed height number, and if so, play around with options after that.
If none of that works, make sure you set padding AND margins on both the custom layout and the EditText to be zero.
Basically the idea is to try these things, get a positive result, then you can remove things one by one to see what really made the change.