-->

如何处理与Android XLARGE屏幕?(How to deal with Android XL

2019-07-30 12:46发布

我公司开发的时钟部件。 看起来在许多设备上的罚款。 除了摩托罗拉XOOM,因为它陷入XLARGE类别。

这是clock.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#00000000"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

<AnalogClock android:id="@+id/AnalogClock" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:dial="@drawable/widgetclock" 
    android:hand_hour="@drawable/widgethour" 
    android:hand_minute="@drawable/widgetminute" /> 

    <!-- Time Row -->
    <LinearLayout
        android:id="@+id/lltimeheaderrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"        
        android:orientation="horizontal"
        android:layout_gravity="center|top"
        android:layout_marginTop="45dp"
        android:visibility="gone">

        <!-- TIME -->
        <LinearLayout android:id="@+id/llTimeDefault"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

            <TextView
                android:id="@+id/HOUR"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/my_gray"
                android:textStyle="bold"
                android:textSize="15sp"/>

            <TextView
                android:id="@+id/MINUTE"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/my_gray"
                android:textStyle="bold"
                android:textSize="15sp" />
            </LinearLayout>

            <TextView
                android:id="@+id/AM_PM"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/my_gray"
                android:textStyle="bold"
                android:textSize="13sp"
                android:padding="1dp" />                        
        </LinearLayout> 
    </LinearLayout>     

    <!-- Calendar Graph -->
    <LinearLayout
        android:id="@+id/llCalGraph"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_gravity="center|left"    
        android:layout_marginLeft="45dp">   
            <FrameLayout android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <ImageView
                    android:id="@+id/CalendarImg"
                    android:src="@drawable/calendar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>                      
                <TextView android:id="@+id/DateDayG"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center|top"
                    android:layout_marginTop="3dp"
                    android:textSize="11sp"
                    android:textStyle="bold"
                    android:textColor="@color/my_gray"
                    android:shadowColor="@color/my_black"
                    android:shadowDx="1"
                    android:shadowDy="1"
                    android:shadowRadius="2"                
                    ></TextView>       
                <TextView android:id="@+id/DateNoG"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="5dp"
                    android:textSize="25sp"
                    android:textColor="@color/my_gray"
                    ></TextView>    
            </FrameLayout>              

    </LinearLayout>             

    <!-- BATTERY -->
    <LinearLayout
        android:id="@+id/llBattGraph"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_gravity="center|right"
        android:layout_marginRight="45dp">              
            <FrameLayout android:layout_width="fill_parent"
                android:layout_height="fill_parent">
                <ImageView
                    android:id="@+id/BatteryImg"
                    android:src="@drawable/batt_00"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>
                <ImageView
                    android:id="@+id/BatteryFlashing"
                    android:src="@drawable/flashing"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginTop="13dp"
                    android:layout_marginLeft="2dp"
                    android:visibility="gone" />                        
                <TextView
                    android:id="@+id/BatteryLevel"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/my_gray"
                    android:textSize="18sp"
                    android:layout_gravity="center" />


            </FrameLayout>              
    </LinearLayout>                     

    <!-- Weather Row -->
    <LinearLayout
        android:id="@+id/llweatherrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"        
        android:orientation="horizontal"
        android:layout_gravity="center|bottom"
        android:layout_marginBottom="45dp"> 

        <!-- WEATHER IMAGE -->
        <LinearLayout
            android:id="@+id/llWeatherImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="visible"
            android:layout_gravity="center">

            <ImageView android:id="@+id/ivWeather"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/w3200"
                />
        </LinearLayout> 

    </LinearLayout>     

</FrameLayout>

基本上,它具有在插件4层的元件。 上层,底层。 左,右部。 我简单地使用的FrameLayout作为基础的布局和各个要素是使用的LinearLayout与重力45dp到每个角上。

这是小工具的外观上的Xoom我期待的元素位置应该是红圈我画。

  1. 什么是最好的布局组合,我应该使用? 你可以建议?
  2. 比方说,我坚持这个布局。 如何为Xoom的设备替代布局? 我试图把clock.xml的布局XLARGE和绘制,XLARGE,但没有...

Answer 1:

最好的和更合适的方法是创建一个文件夹layout-xlarge ,并在那里包括clock.xml当目标设备具有XLARGE布局将被载入。

这样,你就可以根据屏幕大小,密度等,得到了来自开发者文档做出不同的布局http://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts

另一种方案是把所有的大小是在一定45dpXdp到值文件夹中的文件名为dimen ,然后在XML声明为: ...="@dimen/largeButton"并用的方式相同前面提到的创建一个相应的values-xlarge并添加相应的dimen在它的文件。

这是非常有用的机制,因为你可以根据屏幕的大小,创建不同的布局,使它能够获得每大小不同密度像素。 如果你还没有听说过任何这些条款的要求我提供更多的细节。

编辑:从文档

res/layout/my_layout.xml             // layout for normal screen size ("default")

res/layout-small/my_layout.xml       // layout for small screen size

res/layout-large/my_layout.xml       // layout for large screen size

res/layout-xlarge/my_layout.xml      // layout for extra large screen size

res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

你肯定正是这种目录? 具有相同文件名像布局clock.xml无处不在?

第二个编辑评论:

这是更有效,因为在更换仅仅是数字,而不是装载一个完整的布局文件夹中的过渡更加有效,因为你可以猜到。 尽管如此,你可以重复使用的尺寸和不会来回布局中,检查“那是什么尺寸来着?” 就像在一个大按钮的修复尺寸。

而一些更重要的,每个文件夹可以延长具体原因。 如果你想在相同的布局,但不同的维度,那么你应该重写尺寸不能复制粘贴的整个布局。 更有意义,不是吗?

而对于工作几乎是同样的事情。 像layout-large/文件夹,您将有values-large/ 。 有一个在我所提供的文件和在互联网上一个很好的例子。



文章来源: How to deal with Android XLarge screen?