在位图顶部定位Android视图
我有一个可绘制位图的ImageView。每个设备密度(hdpi、xhdpi、xxhdpi等)都有不同版本的位图 我想将文本视图放置在ImageView的顶部,并相对于ImageView的位置。e、 g.从右边30像素,从顶部50像素。TextView需要始终显示在图像的特定部分,因此,对于为不同屏幕密度创建的图像的每个版本,其位置都会有所不同 用像素定位似乎是可行的。我能够为不同版本的图像(hdpi、xhdpi等)创建具有像素值的不同XML布局文件。但是,我无法在dimen.xml中指定px单位在位图顶部定位Android视图,android,android-layout,android-ui,Android,Android Layout,Android Ui,我有一个可绘制位图的ImageView。每个设备密度(hdpi、xhdpi、xxhdpi等)都有不同版本的位图 我想将文本视图放置在ImageView的顶部,并相对于ImageView的位置。e、 g.从右边30像素,从顶部50像素。TextView需要始终显示在图像的特定部分,因此,对于为不同屏幕密度创建的图像的每个版本,其位置都会有所不同 用像素定位似乎是可行的。我能够为不同版本的图像(hdpi、xhdpi等)创建具有像素值的不同XML布局文件。但是,我无法在dimen.xml中指定px单位
用像素定位是正确的方法吗?相对于图像的像素定位是否可以跨不同的设备工作 我会这样做。在图像视图上方放置一个RelativeLayout,并将其颜色设置为“#66cccc”。并在其中放置一个文本视图
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="@drawable/yourImage" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="25dp"
android:background="#66cccccc">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff"
android:text="Test Description" />
</RelativeLayout>
</RelativeLayout>
谢谢。我实际上是在使用一个框架布局来进行z排序。然后我通过设置像素的边距来定位TextView。TextView不能相对定位,它需要使用相对于下方图像的像素绝对定位。这在不同的设备上仍然有效吗?事实上,我从未使用过FrameLayout
,我也不知道你的问题。但我认为您可以创建两个不同的模拟器来查看差异。(谢谢你的支持)。你能详细解释一下图像的哪一部分吗?文本需要始终适合图像的一部分形状。请查看我的ans: