Android中的多屏幕支持

时间:2013-02-28 06:58:49

标签: android android-layout

我正在寻找在Android上修复多种屏幕尺寸布局的最佳途径。我有一个很棒的应用程序,几乎准备好发布..但我的一个合作伙伴尝试在三星平板电脑和图标和一些功能太小

那么我在想什么呢?我在屏幕尺寸上改变分辨率还是有更简单的方法?

这是我的布局代码Any Suggestion会有帮助吗?


    <?xml version="1.0" encoding="utf-8"?>
<merge xmlns:tools="http://schemas.android.com/tools"
xmlns:pj="http://schemas.android.com/apk/res/com.example.waysecure"
xmlns:bm="com.example.waysecure"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"     xmlns:android="http://schemas.android.com/apk/res/android">
<Button
    android:id="@+id/button_pannic"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/pannic"
    android:visibility="visible" />
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="bottom"
    android:layout_marginTop="50dp" >
    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <FrameLayout
        android:id="@+id/Fofo"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </FrameLayout>
    </RelativeLayout>
 <SlidingDrawer
 android:id="@+id/sg_below"
 android:layout_width="match_parent"
 android:layout_height="275dp"
 android:layout_gravity="bottom"
 android:layout_marginTop="200dp"
 android:content="@+id/content"
 android:handle="@+id/handle" >
<Button android:layout_width="match_parent" android:layout_height="60dp" android:id="@+id/handle" android:background="@drawable/tray_handle_normal" />
<RelativeLayout
    android:id="@+id/content2"
    android:layout_width="wrap_content"
    android:layout_height="282dp"
    android:background="#aa000000" >
        </RelativeLayout><TabHost  android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent">
   <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="bottom"
            android:background="#aa000000" >
 <LinearLayout android:id="@+id/tab1" android:layout_width="match_parent" android:layout_height="match_parent">


            </LinearLayout>
              <GridView
                  android:id="@+id/tab2"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_gravity="bottom"
                  android:columnWidth="90dp"
                  android:gravity="center"
                  android:horizontalSpacing="1dp"
                  android:numColumns="auto_fit"
                  android:stretchMode="columnWidth"
                  android:verticalSpacing="1dp" > 
            </GridView>  <LinearLayout android:id="@+id/tab3" android:layout_width="match_parent" android:layout_height="match_parent">
                  <com.carouseldemo.controls.Carousel android:id="@+id/carousel2" android:layout_width="match_parent" android:layout_height="match_parent" android:animationDuration="200" pj:Items="@array/entries" pj:Names="@array/names" pj:SelectedItem="0" pj:UseReflection="true">
                </com.carouseldemo.controls.Carousel>  
            </LinearLayout>
        </FrameLayout>
    <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top" >
        </TabWidget>
    </TabHost>
</SlidingDrawer>
</merge>

5 个答案:

答案 0 :(得分:4)

您需要在res文件夹中为不同的屏幕添加额外的布局。

如果您希望7 inch在res名称中创建布局文件夹为layout-sw720dp

10 inch创建layout-xlarge

layout文件夹中复制所有文件并粘贴文件并调整大小。

使用所有屏幕进行转换和测试。

请参阅更多屏幕的链接

http://developer.android.com/guide/practices/screens_support.html

答案 1 :(得分:1)

您唯一需要做的就是在<support-screens>中添加manifest,以下是<support-screens>

 <supports-screens android:resizeable=["true"| "false"]
              android:smallScreens=["true" | "false"]
              android:normalScreens=["true" | "false"]
              android:largeScreens=["true" | "false"]
              android:xlargeScreens=["true" | "false"]
              android:anyDensity=["true" | "false"]
              android:compatibleWidthLimitDp="integer"
              android:largestWidthLimitDp="integer"/>

创建一致布局的提示:

  1. 不要对任何layout参数进行硬编码,例如widthheight等。
  2. 请勿使用“px”。使用“sp”表示文字大小,使用“dp”表示layout-widthlayout-height等。
  3. 使用RelativeLayoutLinearLayout,不要使用AbsoluteLayout,因为它已被弃用。
  4. ScrollView所需的任何地方使用layouts,因为它支持单一视图。
  5. 有关更多信息,请查看Support Multiple Screens

    的Android开发人员文档

答案 2 :(得分:1)

我为此配置了一种方法。对我来说,这是一个热门和试用方法。当我开发first android application时,同样的问题发生在我身上,但最后,我钉了它。为了完美支持每个屏幕分辨率,在全屏图像的情况下,制作4个不同分辨率的图像:

hdpi: 480*800
ldpi: 320*460
mdpi:720*960
xhdpi: 800*1280

如果您的应用支持这两种方向,则为横向模式制作不同的布局,并在布局中放置相同的名称,并在此link上找到相关信息。

答案 3 :(得分:1)

您必须在res文件夹

中创建layout_size文件夹
  

对于不同大小的屏幕,创建不同的xml文件。

答案 4 :(得分:0)

请提供此功能..这可能会帮助您......感谢device screens and resolutions

相关问题