Use a different layout style on different screens (Android)

I'm having some problems with my single screen layouts not scaling so well, some text popping up from a button, etc.

I thought about a fix, but I need your help.

In my XML, I created:

<style name="styleforS5" parent="android:style/Widget.ImageButton">
    <item name="android:background">@null</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_weight">1.0</item>
    <item name="android:paddingTop">5dp</item>
    <item name="android:paddingBottom">5dp</item>
</style>

<style name="samsungTablet" parent="android:style/Widget.ImageButton">
    <item name="android:background">@null</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_weight">2.0</item>
    <item name="android:paddingTop">15dp</item>
    <item name="android:paddingBottom">5dp</item>
</style>

      

Now my question is this: how can I write that if input tablet, it should use the samsungTablet style, and when its s5 it should use stylefors5?

Thanks for the help, Zak

0


source to share


1 answer


Perhaps the solution should only have one style for both devices, but define it in two specific folders based on the smallest available width (see Multiple Screen Support ):

For smartphones (S5): res / values ​​/styles.xml

<style name="ImageButtonStyle" parent="android:style/Widget.ImageButton">
    <item name="android:background">@null</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_weight">1.0</item>
    <item name="android:paddingTop">5dp</item>
    <item name="android:paddingBottom">5dp</item>
</style>

      



And for Tablet: res / values-sw600dp / styles.xml

<style name="ImageButtonStyle" parent="android:style/Widget.ImageButton">
    <item name="android:background">@null</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_weight">2.0</item>
    <item name="android:paddingTop">15dp</item>
    <item name="android:paddingBottom">5dp</item>
</style>

      

In this folder, Android will choose the "correct" style to use based on the screen size.

0


source







All Articles