Question

I have an ListView, which contains many EditText. Caused by less space, the height of my EditTexts are fixed to 50dp, there is no way to get it bigger. The Background is a stateListDrawable:

private class Background extends StateListDrawable {
    public Background(Context ctx) {

        this.addState(
                new int[] { android.R.attr.state_focused,
                        R.attr.state_error },
                getResources().getDrawable(
                        R.drawable.background_focussed_error));

        this.addState(new int[] { android.R.attr.state_focused },
                getResources().getDrawable(R.drawable.background_focussed));
        this.addState(new int[] { R.attr.state_error }, new ColorDrawable(
                Color.RED));
        this.addState(new int[] { R.attr.state_filled }, new ColorDrawable(
                ctx.getResources().getColor(R.color.grau)));

        this.addState(new int[] {}, new ColorDrawable(ctx.getResources()
                .getColor(R.color.hellgrau)));
    }

}

the drawable R.drawable.background_focused is this one:

<?xml version="1.0" encoding="utf-8"?>

<solid android:color="@color/grau" />

<stroke
    android:width="4dp"
    android:color="@color/dunkelgrau" />

<corners
    android:bottomLeftRadius="10dp"
    android:bottomRightRadius="10dp"
    android:topLeftRadius="10dp"
    android:topRightRadius="10dp" />

</shape>

If I focuse the EditText on a large display, where height is set to "wrap_content", it looks like:
IMAGE OK

(I want to post an image, but I need a 10 reputation, so I post a link to this image)

Buuuuuut, if I focuse the EditText on a small Display, where height is fixed set to 50dp (cause it have to show at least 5 items in the listView) it looks like:
IMAGE NOT OK

the top and the bottom lines are missing. I tried to set the corner-radius to 1 px etc, but it does not effect my problem. Can anyone help me please?

Was it helpful?

Solution

Setting the height is ignored if the contents are too large. In this case the text height, including padding, etc. causes the contents to exceed the available space.

You need to set the textSize of the EditText smaller in order to have the layout draw without truncating, use a different font or change how the text is displayed within the EditText (like reducing padding, which could look bad but might work - e.g. if you are only displaying numbers, you don't need padding beneath the bottom of the text for letters like "g").

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top