方案
我正面临与google nexus中导航栏相关的问题。 在我的片段中,我有一个图像视图(从当地资源中显示,例如:cofee mug) 和包含描述的标签(基本上是带文字的按钮视图)。两个视图都在布局中。 标签位于dp左侧和顶部的一定边距,因此标签看起来就像图像的正下方。
咖啡杯图像已根据xhdpi分辨率进行切片。
遇到问题
当应用程序在xhdpi设备(如s3)上运行时,标签正好在预期的咖啡杯图像下方。但是当在包含导航栏的谷歌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"/>
图像视图是上面提到的coFfee马克杯图像,按钮视图是标记(蓝色图像)。两者都在相对布局父级内部,其高度和宽度匹配父级。
预期: