2013-08-02 159 views
3

嗯,我有activity.xml我有一个背景图像和一个按钮,它也有一个背景图像在普通屏幕上运行良好,但是当我在xlarge上运行它时或大屏幕按钮的位置改变如何使Android应用程序适合所有屏幕尺寸

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" 
    android:background="@drawable/menu" 
    android:layout_margin="@dimen/my_view_margin" 
    > 

    <LinearLayout 
     android:layout_width="300px" 
     android:layout_height="200px" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="172dp" 
     android:orientation="vertical" > 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="60px" 
      android:background="@drawable/bt" 
      android:text="Button" /> 
    </LinearLayout> 

</RelativeLayout> 

这是代码的上方和下方是不同的画面的图像

不能增加图象引起不必须足够的声誉

+0

首先,你将要开始使用'dp'值,而不是'px'值。并且,阅读这些链接。绰绰有余,以达到你所期望的。 http://developer.android.com/guide/practices/screens_support.html和http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html –

+1

是的使用DP而不是PX。为什么这个线性内部相对? 不要修复高度,宽度这是更大的设备的问题.. –

+0

试试我的答案它应该适用于所有设备.. –

回答

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

将此添加到您的清单文件的应用程序。

+1

这不是问题..与布局的问题.. 如果UI不支持,他可以没看到任何东西.. –

+0

那就是全部?清单中还有其他的东西吗? –

1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="@dimen/my_view_margin" 
    android:background="@drawable/menu" 
    tools:context=".MainActivity" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="60dp" 
     android:layout_marginTop="170dp" 
     android:layout_centerHorizontal="true" 
     android:background="@drawable/bt" 
     android:text="Button" /> 

</RelativeLayout> 
0

很简单,使用相对布局和设定的保证金代码。设置每个文本视图,按钮等之间的边距,每部手机看起来都一样。

android:layout_marginTop="10dp" 
// change Top to Bottom, Left or Right for what you need. 
5

使用重量为所有的布局,而不是给定值,因为重量是默认支持屏幕视图screen.In明显的类型%是真的。

如果你觉得任何时候,这是不可能比增加梦诗值{文件夹包含dimens.xml}