繁体   English   中英

其他android手机中的应用程序更改的布局

[英]layout of application changes in other android phones

这是我的代码。 相同的代码已安装在许多设备中,布局也不是完全相同。我使用了相对布局并具有拖放对象。 但是,即使拖放对象,代码也应在所有设备上都能正常工作。

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/room1"
    android:background="@drawable/room1"
    android:layout_above="@+id/textView8"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />
<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:id="@+id/load"
     android:background="@drawable/load1"
    android:layout_above="@+id/textView10"
    android:layout_alignLeft="@+id/textView2"
    android:layout_alignStart="@+id/textView2" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="About"
    android:id="@+id/appbutton"
    android:layout_alignParentBottom="true"
    android:layout_alignRight="@+id/textView10"
    android:layout_alignEnd="@+id/textView10" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/employee"
    android:background="@drawable/employee"
    android:layout_above="@+id/textView8"
    android:layout_alignLeft="@+id/textView8"
    android:layout_alignStart="@+id/textView8" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Send Message to all members"
    android:id="@+id/allmessage"
    android:layout_alignBottom="@+id/appbutton"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/status"
    android:id="@+id/status"
    android:layout_below="@+id/imageView2"
    android:layout_alignLeft="@+id/employee"
    android:layout_alignStart="@+id/employee" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="FAMILY"
    android:id="@+id/textView8"
    android:textColor="#018F99"
    android:paddingBottom="15dp"
    android:layout_centerVertical="true"
    android:layout_alignLeft="@+id/emergency"
    android:layout_alignStart="@+id/emergency"
    android:paddingLeft="10dp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="EMERGENCY"
    android:id="@+id/textView2"
    android:textColor="#FF0000"
    android:layout_below="@+id/emergency"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="LOADSHEDDING\n     SCHEDULE"
    android:id="@+id/textView10"
    android:layout_above="@+id/appbutton"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:textColor="#020202" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/room2"
    android:background="@drawable/room2click"
    android:layout_alignTop="@+id/emergency"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/gate"
    android:background="@drawable/gateclick"
    android:layout_below="@+id/textView2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/imageView2"
    android:layout_alignParentTop="true"
    android:layout_toStartOf="@+id/appbutton"
    android:background="@drawable/homeautomation1"
    android:layout_alignRight="@+id/appbutton"
    android:layout_alignEnd="@+id/appbutton"/>

</RelativeLayout>

在此处输入图片说明

这是因为每个设备都有不同的分辨率和PPI。 因此,基本上可以通过多种方法来完成所需的任务。 1)使用线性布局并尝试“权重”。 它将屏幕分为多个部分,布局不会在其他设备上生效。 2)使用不同的布局文件。(就像我们之前在eclipse中所做的一样)3)对values.xml使用不同的文件4)有一个名为“ sdp”的自定义库,它将为您自动执行任务。 只需在互联网上搜索即可。

暂无
暂无

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

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