2

I am currently trying to get some kind of dynamic credit card picture, but what I want is to be able to set the numbers and the creditcard, which is an imageview. Now I need my textview to be at the same location for all screensizes, but I have trouble achieving this.

Can anyone point me in the right direction? Or maybe share a better way with me? This is what I got now:

<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"/>

Here is an image of the idea:

CreditCard preview

Thanks!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Sam
  • 95
  • 11

1 Answers1

1

You can follow the following steps

  1. Have a reference view of fixed size.
  2. Draw text on that view.Since the view is of fix size-the text will be drawn always at correct location.
  3. Now convert the reference view and overlapping textview into a bitmap.
  4. Now set this bitmap to actual image view.This image view along with text will scale as per current device configuration.

You can also set adjustViewBonds and other properties so that the aspect ratio of the imageview doesnt change.

rupesh jain
  • 3,410
  • 1
  • 14
  • 22
  • What if I want to be able to change the text portrayed on the imageview multiple times during my activity, live. Then I can't use bitmaps right? because that would be static content? – Sam May 01 '17 at 20:02