0

在此处输入图像描述

设想

我遇到了与 google nexus 中的导航栏相关的问题。在我的片段中,我有一个图像视图(从本地资源显示,例如:咖啡杯)和一个包含描述的标签(基本上是带有文本的按钮视图)。两个视图都在布局内。标签在 dp 中从左侧和顶部以一定的边距定位,因此标签看起来就像在图像下方。

咖啡杯图像已针对 xhdpi 分辨率进行了切片。

面临的问题

当应用程序在 xhdpi 设备(如 s3)上运行时,标签正好在咖啡杯图像下方,如预期的那样。但是当在包含导航栏的 google nexus 3 上运行时,由于导航栏消耗一定数量的像素,图像被缩放渲染。但由于某种原因,我的标签位置错误。

如何确保标签没有错位?如果您能提供一些建议,我将不胜感激。

布局如下所示:

    <ImageView
        android:id="@+id/home_background"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:adjustViewBounds="true"
        android:contentDescription="@string/image" />


    <Button android:id="@+id/discoverTitle" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:background="@drawable/tag_states"
        android:layout_marginLeft="17dp"
        android:layout_marginTop="18dp"
        android:textSize="30sp"
        android:textColor="#515151"/>

图像视图是上面提到的咖啡杯图像,按钮视图是标签(蓝色图像)。两者都在相对布局父级内,高度和宽度匹配父级。

预期的:

实际的

4

0 回答 0