如何在安卓中为不同的屏幕设置布局支持?

3
我是一名开发人员,正在使用GridView开发画廊视图。在小屏幕上,我的布局设计非常好,但在大屏幕上,我的设计不太适合。在大屏幕上,“加载更多图片”按钮下方有一些空白,如图2所示。请问如何解决这个问题?我的Manifest文件中添加了以下代码来支持各种屏幕,请给我提供一些样例代码。

alt text

alt text

<supports-screens android:largeScreens="true"
 android:normalScreens="true" android:smallScreens="true"
 android:anyDensity="false" /> 

以及我的XML代码

<?xml version="1.0" encoding="utf-8"?>
<merge android:layout_width="wrap_content" android:layout_height="340dp" xmlns:android="http://schemas.android.com/apk/res/android">
 <LinearLayout  android:id="@+id/LinearLayout01"  
 android:layout_width="fill_parent" 
 android:layout_height="335dp" android:orientation="vertical" 
 android:background="@color/black">


 <GridView 
                    android:id="@+id/jr_lookbook_grid" android:layout_width="fill_parent"
                    android:layout_height="335dp" android:numColumns="4"
                    android:verticalSpacing="10dp" android:horizontalSpacing="10dp"
                    android:columnWidth="90dp" android:stretchMode="columnWidth"
                    android:adjustViewBounds="true"
                    android:background="@drawable/shape"  
                    android:gravity="center"  android:layout_weight="1"/>
</LinearLayout>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout0209_img"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center"
    android:paddingTop="311dp">
         <Button  android:id="@+id/click"
                android:background="#AA000000" 
                   android:text="Load More Pictures..."
                  android:textColor="@color/white"                  
                   android:layout_width="fill_parent" android:layout_height="30dp"/>
    </LinearLayout>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/LinearLayout02_img"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_gravity="center"
    android:layout_alignParentBottom="true"
    android:background="@color/black"
                android:layout_alignParentLeft="true"> 
   <WebView 
        android:id="@+id/webview"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"         
        android:scrollbars="none" />
    <ImageView android:id="@+id/ImageView01" 
    android:layout_gravity="center_horizontal"
    android:scaleType="centerInside"
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent"
    android:adjustViewBounds="true">
</ImageView>  
    </LinearLayout>
   <LinearLayout android:id="@+id/LinearLayout02"     android:background="#AA000000" 
         android:layout_width="400px"
        android:layout_height="50dp"
        android:layout_gravity="bottom">
 <Button
    android:id="@+id/back
                android:layout_height="wrap_content"
               android:background="@drawable/back1"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="10dp" /
                 <Button
                  android:background="@drawable/forward5"
                android:id="@+id/next"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="150dp"/>
                  <Button
                  android:background="@drawable/menushare"
                android:id="@+id/photoshare"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:layout_alignParentRight="true"
                android:layout_marginLeft="20dip" />
</LinearLayout>
</merge>

感谢大家。
2个回答

3

您需要为大屏幕编写xml代码。我想您将xml文件保存在res/layout文件夹中。如果是这样,您可以保留三个文件夹以区分各种屏幕,如res/layout-small、res/layout和res/layout-long。在这三个文件夹中,您可以为各种屏幕类型设置不同的对齐方式。对于中等大小的屏幕,请将您的xml代码保存在layout文件夹中,对于小屏幕,请将其保存在layout-small中等等。

    <supports-screens
    android:smallScreens="true"
    android:normalScreens="true"
    android:largeScreens="true"        
    android:anyDensity="true" />

请在您的AndroidManifest.xml文件中添加以下行:


谢谢。对我很有帮助。 - Freelancer

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接