And*_*oid 90 android android-image android-imageview
我有一个带有图像的imageView,在我要放置文本的图像上.我怎样才能做到这一点?
Ale*_*qui 158
这就是我做的方式,它完全按照你在RelativeLayout中的要求工作:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativelayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/myImageSouce" />
<TextView
android:id="@+id/myImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/myImageView"
android:layout_alignTop="@id/myImageView"
android:layout_alignRight="@id/myImageView"
android:layout_alignBottom="@id/myImageView"
android:layout_margin="1dp"
android:gravity="center"
android:text="Hello"
android:textColor="#000000" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
mar*_*tar 15
你可能想从不同的方面采取if:在背景上使用带有drawable的TextView似乎更容易:
<TextView
android:id="@+id/text"
android:background="@drawable/rounded_rectangle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</TextView>
Run Code Online (Sandbox Code Playgroud)
你可能
onDraw.首先调用super.onDraw()该方法如果你这样做,你可以将它作为单个布局组件使用,这样可以更容易地与其他组件一起布局.
有很多方法.您使用RelativeLayout或AbsoluteLayout.
使用相对,您可以让图像与左侧的父对齐,并且也可以将文本与父对齐对齐...然后您可以在文本视图上使用边距和填充以及重力将其排列在您的位置想要超过图像.