2013-06-28 76 views
5

我使用模拟器大小的平板电脑布局从xml制作了布局。但是,当在Android手机设备上的相同布局打开,然后每件事情扭曲,所以我可以做一个XML设计,可以在设备手机和平板电脑也很好地工作。请建议我,感谢您的回答。我如何制作可在平板电脑和手机中使用的布局?

+0

您将不得不为两种屏幕尺寸设计布局和绘图。检查文档有你需要的所有信息http://developer.android.com/guide/practices/screens_support.html – Raghunandan

+2

我已经在这里给出了详细的答案:http://stackoverflow.com/a/12742888/1369222 –

+0

请参阅[本](http://stackoverflow.com/questions/14078460/android-how-to-scale-a-layout-with-screen-size/19925666#19925666)回答。 –

回答

11

让你的资源如此。

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

RES /布局小/ my_layout.xml //布局小屏幕尺寸

RES /布局大/ my_layout.xml //布局大尺寸屏幕

RES /布局XLARGE/my_layout.xml //布局超大屏幕SI泽

RES /布局XLARGE土地/ my_layout.xml //在横向布局特大型

RES /绘制-MDPI/my_icon.png //位图中密度

RES /抽拉-HDPI/my_icon.png //位图用于高密度

RES /抽拉-xhdpi/my_icon.png //位图超高窝点ity

欲了解更多referencereference1

在你的manifest.xml添加此

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

希望这会帮助你。

+0

所有可绘制文件夹中的图像大小将相同?或者将在每个布局中放置不同大小的图像? –

+0

你应该放置不同大小的图像。根据密度..因为小图像只适合小屏幕。但它不适合较大的屏幕,因为它看起来非常小。所以我们正在像这样移动。最好放置不同大小的图像。 – Nirmal

+0

@Nirmal嗨,我也用这个,但没有得到解决方案。我的设备只能显示正常的布局。我已经添加了这个权限'android:configChanges =“orientation | keyboardHidden | screenSize | screenLayout”'这会影响任何东西。 – SathishKumar

0

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

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> 
+0

这对我有帮助吗? –

+0

这使得您的布局内部有一定比例的页面。因此无论是在电视屏幕上还是在最小的设备上,纵横比都是一样的。 – SmulianJulian

+0

嗯,我会推荐你​​使用片段... –

相关问题