繁体   English   中英

手机上的android布局混乱

[英]android layout messed up on the phone

我是基于模拟器进行布局的,但只是在实际设备上运行了我的应用程序,所以所有布局都弄乱了。 我不知道该如何解决。 这是我的xml文件的代码,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/mainback" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="23dip"
    android:layout_marginRight="15dip"
    android:layout_marginTop="255dip"
    android:orientation="vertical" >

    <TextView
        android:layout_width="276dp"
        android:layout_height="132dp"
        android:textSize="15dp"
        android:gravity="center_vertical"
        android:text="some text"
        android:textColor="#4C2016"/>

    <Button
        android:id="@+id/special"
        android:layout_width="131dp"
        android:layout_height="40dp"
        android:background="@drawable/cc"
        android:layout_marginTop="20dip"
        android:layout_marginLeft="75dip"
        android:textSize="17dp"
        android:textStyle="bold"
        android:text="Specials"
        android:textColor="#F6E6C6" />
</LinearLayout>

`

有人告诉我如何修复此代码真是太棒了

这是xml文件外观的快照

在此处输入图片说明

这是手机上的样子,

在此处输入图片说明

图像和橙色文本是背景图像的一部分,并且textview和button已添加到视图中。

您正在使用哪个API级别? 因为我看到您在同一文件中使用“ fill_parent”和“ match_parent”。 从API级别8开始,fill_parent替换为math_parent。 在API级别低于8(无法识别”的项目中使用match_parent时,我也遇到了问题,反之亦然,fill_parent在API 8或更高版本的项目中给我带来布局问题。

但是为了更好地帮助您,请发布一些正在运行的APP的屏幕截图。 因此,我们可以更好地了解您的布局问题。

有不错的发展!

硬编码的值使布局看起来根据设备的屏幕尺寸和分辨率而有所不同。

您可以将图像放在ImageView中,而不是依靠边距在图像下方放置文本(“ android:layout_marginTop =“ 255dip”)。 然后,您的TextView将位于图像下方。 使用imageview的底部边缘或textview的顶部边缘微调距离。

将'wrap_content'用于TextView的* layout_height *,将'fill_parent'用于* layout_width *,而不是固定值。

另外-如果您的应用程序的目标API低于8,则将“ match_parent”替换为“ fill_parent”。

<LinearLayout>
    <ImageView/>
    <TextView/>
    <Button/>
</LinearLayout>

暂无
暂无

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

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