1

I'm working on an app which is intended to run on a single size screens, and has a pretty complex design so to make things easier I'm working with absolute sizes for everything.

The problems start when I specify a very small size for views, Android does not seem to adapt the content to these small sizes. I have 3 examples here:

  • 90x70px EditText: EditText Even though I used a small text size, the text is not centered well... How do I center it?
  • 200x80px Spinner: Spinner There's plenty of available space to the right. How can I use it?
  • 50x50px CheckBox: CheckBox We see just 1 corner instead of the full box... Why?
Jong
  • 9,045
  • 3
  • 34
  • 66
  • 1
    the issue here is with the default resources in the android framework. For the edittext, it is a 9-patch with intrinsic paddings. You'll need to add your own images without such paddings. you can find the original resources in AOSP. – njzk2 Nov 20 '13 at 21:24
  • For the edittext try edittext.setGravity(Gravity.CENTER_VERTICAL); edittext.setGravity(Gravity.CENTER_HORIZONTAL); – support_ms Nov 21 '13 at 07:02

4 Answers4

0

Android does not seem to adapt the content to these small sizes

After a specific min size is achieved Android won't adopt, I strongly suggest you to consider using ScrollView and change you layouts but if you still insist then try this:

  • Set the background of EditText to null and you will understand that it was all due to the padding of 9 patch background. After that go to Android Asset Studio and create smaller background or you can do it in xml drawable as well, check this link. To center the text use android:gravity="center" on EditText.

  • Same 9 patch background issue as described above, bacground image of spinner is made this way to put its content on left of arrow after addiing certain padding. Try setting background to your custom less padded 9 patch.

  • Same issue, just make smaller drawables for your CheckBox. Consult this link.

Community
  • 1
  • 1
M-Wajeeh
  • 17,204
  • 10
  • 66
  • 103
0

have you tried to use padding? I have used negative values to move controls out of the screen. The same might be true for padding? Good luck mate

Lunchbox
  • 1,538
  • 2
  • 16
  • 42
0

Try using the following overrides in TextView-derived classes...worked for me:

    @Override
    public int getCompoundPaddingTop() {
        return 1;
    }

    @Override
    public int getCompoundPaddingBottom() {
        return 1;
    }

    @Override
    public int getCompoundPaddingLeft() {
        return 1;
    }

    @Override
    public int getCompoundPaddingRight() {
        return 1;
    }
Merk
  • 1,441
  • 1
  • 15
  • 28
0
  • Android doesn't support these small view because it uses its intrinsic values as default. I would also suggest you to make some larger views. It would be better for the users too.
  • When u design some views, user perspective is the very imp factor. You should always design the UI with user in your mind.

Well apart from this if you still want to use these things follow these :

  • To center the text use android:gravity to center in EditText.
  • Use smaller drawables for your checkbox and spinner.
  • You can also make custom shapes in XML in drawable folder and use those as background to your views. Also set padding 1 or negative to the best results.
Jatin Malwal
  • 5,133
  • 2
  • 23
  • 26