4

好吧,我有 activity.xml 我有一个背景图像和一个按钮,其中也有一个背景图像在普通屏幕上运行良好,但是当我在 xlarge 或大屏幕上运行它时,按钮的位置会改变

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

这是上面的代码,下面是不同屏幕的图像

无法添加图像,因为没有足够的声誉

4

6 回答 6

5

对所有布局使用权重而不是给出恒定值,因为权重是屏幕的一种 % 类型。在清单中默认支持屏幕视图为 true。

如果您认为任何时候,添加尺寸值 {folder contains dimens.xml} 是不可能的

于 2013-11-16T07:53:38.547 回答
3

这些链接将帮助您为多个屏幕创建应用程序:

  1. http://developer.android.com/training/multiscreen/screensizes.html

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

这些是 android 关于实现对多种屏幕尺寸的支持的官方文档。

于 2013-08-02T04:56:52.007 回答
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>
于 2013-08-02T05:10:42.090 回答
1
<supports-screens android:smallScreens="true" 
          android:normalScreens="true" 
          android:largeScreens="true"
          android:xlargeScreens="true"
          android:anyDensity="true" />

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

于 2013-08-02T04:57:18.273 回答
0

很简单,使用带有设置边距代码的相对布局。设置每个文本视图、按钮等之间的边距,它在每部手机上看起来都一样。

android:layout_marginTop="10dp" 
// change Top to Bottom, Left or Right for what you need.
于 2013-08-02T07:14:45.987 回答
0

使用相对布局,绘制 9 张图像。对于高质量的应用程序,您可以为所有 4 种屏幕尺寸创建不同的布局 XMLS。http://developer.android.com/guide/practices/screens_support.html使用此链接了解更多信息。

于 2013-08-02T04:55:00.197 回答