gpt4 book ai didi

Android 将 TextView 保持在 ImageView 内的固定位置

转载 作者:行者123 更新时间:2023-11-29 01:10:12 26 4
gpt4 key购买 nike

我目前正在尝试获取某种动态信用卡图片,但我想要的是能够设置数字和信用卡,这是一个 ImageView 。现在我需要我的 TextView 在所有屏幕尺寸的相同位置,但我很难实现这一点。

谁能指出我正确的方向?或者与我分享更好的方法?这是我现在得到的:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
android:padding="10dp">

<ImageView
android:id="@+id/creditcardimage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
app:srcCompat="@drawable/creditcardblue"/>

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/creditcardimage"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="81dp"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:text="1234 5678 9876 5432"
android:textSize="20sp"/>

这是这个想法的图片:

CreditCard preview

谢谢!

最佳答案

您可以按照以下步骤操作

  1. 有一个固定大小的引用 View 。
  2. 在该 View 上绘制文本。由于 View 具有固定大小,因此将绘制文本始终在正确的位置。
  3. 现在将引用 View 和重叠 TextView 转换为位图。
  4. 现在将此位图设置为实际 ImageView 。此 ImageView 与文本一起将根据当前设备配置进行扩展。

您还可以设置 adjustViewBonds 和其他属性,以便 imageview 的宽高比不会改变。

关于Android 将 TextView 保持在 ImageView 内的固定位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43725187/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com