3

I created a custom preference but its paddings do not look like paddings of a standard preference. Does anybody know a way how they can be added without playing with numbers? On the pic with the blue background is a new preference item without preset paddings.

Custom preference with blue background

After testing on several devices found out that on different devices standard paddings are different. It makes UI inconsistent if paddings were set up manually.

Maxim
  • 4,152
  • 8
  • 50
  • 77

3 Answers3

1

This looks like a duplicate, the answer to this question might be able to help you.

Custom preference, targetSdkVersion="11": missing indent?

Community
  • 1
  • 1
HandlerExploit
  • 8,131
  • 4
  • 31
  • 50
  • 1
    Sorry for unchecking, it didn't solve my problem in the end. CommonsWare described example when custom preference extends standard preference. In his case it is DialogPreference. In my case I want to add different layout to a custom preference as a result my preference extends base "Preference" class. Trying his solution I didn't get my preference intended. – Maxim Dec 05 '11 at 20:45
1

Intent on the left side is a place for an icon. Preference layout has its own margins for the content. If I inflate my own layout I have to define spaces and margins by my own, layout cannot be inherited partially. However Preference has a "widgetLayout" layout which takes the rest of the space on the right side of the preference control. This space can be customized with preferred layout.

Maxim
  • 4,152
  • 8
  • 50
  • 77
0

You generally want to leave the default view elements alone unless you have a good reason to change them.

The padding for 3.x is somewhat different because it is using a larger screen.

You might try specifying different layouts for different size screens and see if that works better for you.

The important thing to remember is: the devices UI defaults are more important than your defaults. This is not iOS. You are sending your app out into the wild, where there are going to be all sorts of crazy screen sizes, and you should program the app as such.

On a side note, the other option is to use display-independent pixels to specify your sizes, but it's almost always better to describe things in percentages and ratios.

Hope this helps!

Codeman
  • 12,157
  • 10
  • 53
  • 91
  • I do have a good reason, I need to create a custom preference that will have different layout than what android offers among its set of standard preferences. I wish my custom layout can inherit standard preference style. Manufacturers customize UI and override standard styles, I won't be able to test my custom preference layout on every device to find different style sizes for each manufacturer. Doesn't matter what I'll be using pixels or percentages it won't save the problem, standard preferences will have different indents than custom. – Maxim Nov 08 '11 at 21:58