Ryan
Ryan

Reputation: 957

Drawable issue with theme

When building my app, I started just using the Theme.Light.NoTitleBar.Fullscreen theme. I built all my layouts for the whole app like this, and got things to look how I want them. Some drawables used in the layouts have their size specifically set, and others are set to wrap_content.

I then decided to switch to the Holo light theme. When I do this, all the drawables used in layouts that are set to wrap_content end up larger. Almost as if they are pulling from a larger bucket. In fact, some look like they've been stretched.

Holo Based Theme

Default PreHolo Theme

I know the background is black in the older theme one, but that's not an issue (this is actually a layout file that is included in another layout). Obviously there's quite a difference in size between the two.

Upvotes: 8

Views: 493

Answers (4)

Zhenghong Wang
Zhenghong Wang

Reputation: 2127

From android's source code, see https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml
The style which your button will be used in Holo.Light is

<style name="Widget.Holo.Light.Button" parent="Widget.Button">
    <item name="android:background">@android:drawable/btn_default_holo_light</item>
    <item name="android:textAppearance">?android:attr/textAppearanceMediumInverse</item>
    <item name="android:textColor">@android:color/primary_text_holo_light</item>
    <item name="android:minHeight">48dip</item>
    <item name="android:minWidth">64dip</item>
</style>

See the last two lines. It has default minHeight and minWeight. That's why your button is stretched.

Solutions
1. Set minHeight and minWidth of your Button to 0.
2. Use a custom style like this.

<style name="MyHoloLightButtonStyle">
    <item name="android:background">@android:drawable/btn_default_holo_light</item>
    <item name="android:textAppearance">?android:attr/textAppearanceMediumInverse</item>
    <item name="android:textColor">@android:color/primary_text_holo_light</item>
</style>

3. Use a ImageButton, and set your images by setImage*(not setBackround*) method.

Upvotes: 0

sergej shafarenka
sergej shafarenka

Reputation: 20416

Here is just my guess based on what I read in this thread.

It can be because you use those images as background property of Button views. This is not safe because depending on default margin values - which are defined in the Theme - Buttons can stretch background images as they need to. If this is the case, then you need to use ImageButton views instead and use setImage*() method to assign images. There you can use scaleType property as it was mentioned by Carlos Robeles.

Upvotes: 1

nKn
nKn

Reputation: 13761

My guess is that for some reason, the Holo theme is rendering your images in a lower resolution than Light. I mean that for instance you have your drawables in the drawable-xhdpi and Holo is treating them as drawable-hdpi. In fact, I don't have any evidence of that, but recently I've been messing around with resolutions and the difference seems very familiar to me.

If you don't have your drawables in the drawable-xxhdpi (the biggest resolution) folder, you could try putting them into a higher lever resolution folder, to see what happens.

Upvotes: 0

Carlos Robles
Carlos Robles

Reputation: 10947

The only thing that comes to my mind, is that the different themes has different values for the defaultandroid:scaleType attribute of the image views.

Please, try specifying the attribute as some that is good for you, and see what happens using the 2 different themes. For example you can use android:scaleType="center", so your ImageViews would be something like

   <ImageView 
          android:scaleType="center"
          android:width="wrap_content"
          android:height="wrap_content"
          android:src="...

Yo can take a look at the different scale types in the ImageView reference: http://developer.android.com/reference/android/widget/ImageView.html#attr_android:scaleType

It is not easy to understand what's the meaning of every type, so the best is to take a minute to play with them

Upvotes: 0

Related Questions