繁体   English   中英

如何使我的布局适合所有屏幕

[英]How to make my layout fit in all screens

我在库存溢出和链接方面经历了许多相对答案,例如支持不同的屏幕屏幕兼容模式
我创建了以下相对布局,并试图使它在所有android屏幕中看起来都一样。

我的图像非常适合4.8英寸手机,但是当我尝试使用2.8英寸显示器或类似的东西时,某些按钮会叠在其他按钮上,并且不会缩水。
有没有人建议如何改进它?
并且最好不要增加我的应用程序的大小。

提前致谢!

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:mm="http://millennialmedia.com/android/schema"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    tools:context=".MainActivity" >

    <ImageButton
        android:id="@+id/Switch_off"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:onClick="someMethod"
        android:background="@drawable/switch_off"/>

    <ImageView
        android:id="@+id/warning_shot"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/more"
        android:onClick="someMethod" />

    <ImageView
        android:id="@+id/imageViewBatteryState"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"        
        android:layout_below="@+id/Switch_off"

        />

   <ImageView
        android:id="@+id/sh"
        android:layout_width="147dp"
        android:layout_height="54dp"
        android:layout_below="@+id/Switch_off"
        android:layout_centerHorizontal="true"
        android:background="@drawable/me"/>

    <ImageView
        android:id="@+id/sit"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:layout_below="@+id/Switch_off"
        android:layout_centerHorizontal="true"
        />

    <TextView
        android:id="@+id/textViewBatteryInfo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:textSize="12sp"
        android:textStyle="bold"
        android:typeface="monospace" 
        android:layout_alignBottom="@+id/sit"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>

我建议您专门针对此问题使用LinearLayout而不是Relativelayout:

我的图像非常适合4.8英寸手机,但是当我尝试使用2.8英寸显示器或类似的东西时,某些按钮会叠在其他按钮上,并且不会缩水。

因为当您为Linearlayout设置方向时 ,其子级将永远不会在任何分辨率或屏幕尺寸上相互重叠。

而且,如果您赋予它们权重,则每个设备的视图都将处于固定位置。

例如,将Xml下面放在您的项目中,然后以“任何分辨率”将其出,它将得到相同的结果。

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:mm="http://millennialmedia.com/android/schema"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button 1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button 2" />

        <Button
            android:id="@+id/button3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button 3" />
    </LinearLayout>

</LinearLayout>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM