不同的屏幕上使用不同的布局风格(Android版) [英] Using different layout style on different screens (Android)

查看:155
本文介绍了不同的屏幕上使用不同的布局风格(Android版)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题,我在一个屏幕上布局,它不能很好地重新调整,一些文本从弹出按钮等...

I am having some problems with my layouts on one screen it's not well rescaled, some text pop- out of the button etc...

我觉得这个修复的,但我需要你对这个帮助。

I thought of a fix for this but i need your help on this.

在我的XML我已创建:

In my XML i have 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>

现在我的问题是下一:我怎么能写,如果输入的是一个平板电脑它应该使用samsungTablet风格,当它的S5它应该使用stylefors5

Now my question is next : how can i write that if the input is a tablet it should use samsungTablet style and when its an s5 it should use stylefors5?

感谢您的帮助,
扎克

Thanks for you help, Zak

推荐答案

也许解决方案是只有一种形式两个设备,但基于最小可用宽度在两个特定的文件夹把它定义(见的支持多屏幕):

Maybe the solution is to have only one style for both devices but define it in two specific folder based on smallest available width (See Supporting Multiple Screen) :

对于智能手机(S5):RES /价值/ 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>

和对片:RES /价值观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>

使用这些文件夹Android系统会选择正确的风格来使用根据屏幕大小。

With these folder Android system will choose the "correct" style to use based on screen size.

这篇关于不同的屏幕上使用不同的布局风格(Android版)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆