我如何制作适用于平板电脑和手机的布局?

时间:2013-06-28 05:16:20

标签: android layout tablet

我使用平板电脑布局模拟器大小从xml进行布局。但是当在Android手机设备上以相同的布局打开然后每个东西都扭曲了,那么我可以制作一个xml布局,它也可以在设备手机和平板电脑上正常工作。请建议我,谢谢你的回答。

4 个答案:

答案 0 :(得分:12)

让你的资源像这样。

res / layout / my_layout.xml //正常屏幕尺寸的布局(“默认”)

res / layout-small / my_layout.xml //小屏幕尺寸的布局

res / layout-large / my_layout.xml //适用于大屏幕尺寸的布局

res / layout-xlarge / my_layout.xml //超大屏幕尺寸的布局

res / layout-xlarge-land / my_layout.xml //横向格式超大的布局

res / drawable-mdpi / my_icon.png //中等密度的位图

res / drawable-hdpi / my_icon.png //高密度位图

res / drawable-xhdpi / my_icon.png //用于超高密度的位图

了解更多referencereference1

在manifest.xml中添加

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

希望这会对你有所帮助。

答案 1 :(得分:1)

使用表格和权重在平板电脑上创建相同或相似的宽高比。我只会创建不同的布局作为最后的手段。

<TableRow
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight=".33" >
             //Note: You will need some other TableRows fill in the difference of this Table Row..2 more of the same will equal 1.
        <TextView
            android:id="@+id/x"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="3dp"
            android:layout_weight=".33"
            android:background="@drawable/buttonx"
            android:gravity="center"
            android:text="Words"
            android:textColor="#ffffff"
            android:textSize="16sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/x2"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="3dp"
            android:layout_weight=".33"
            android:background="@drawable/buttonx2"
            android:gravity="center"
            android:text="Other Words"
            android:textColor="#ffffff"
            android:textSize="16sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/x3"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_marginLeft="3dp"
            android:layout_weight=".33"
            android:background="@drawable/buttonx3"
            android:gravity="center"
            android:text="More Words"
            android:textColor="#ffffff"
            android:textSize="16sp"
            android:textStyle="bold" />

    </TableRow>

答案 2 :(得分:1)

为手机或平板电脑制作两个单独的布局,只需使用默认的布局设计,然后点击预览方向,然后点击创建平板电脑版本即可。然后会看到Tab和Mobile两种布局,这是最简单的。enter image description here

答案 3 :(得分:0)

您可以为手机和标签创建两个单独的布局。您需要做的是为手机创建一个带有“文件名”的布局文件,并通过右键单击项目并选择新的&gt; android xml布局文件&gt;来创建布局文件。然后键入“filename”,单击“下一步”并从右侧窗格中选择“大小”,然后从下拉列表中选择“x-large”。选项卡的布局文件是单独创建的,因此单独定制您的布局。