I am trying to create a fake LCD display.
It should exist of some normal text, showing some data, and a background, faking that LCD look:
I wrote this xml, aligning 3 TextViews on top of each other.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/footer_linearLayout_footer_parent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/dashboard_bottom_background"
android:gravity="center"
android:padding="3dip" >
<TextView
android:id="@+id/textView_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:ellipsize="none"
android:lines="1"
android:text="text"
android:textColor="@color/holo_blue_light"
android:textSize="28dip" />
<TextView
android:id="@+id/textView_heading2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0.15"
android:ellipsize="none"
android:gravity="center"
android:lines="1"
android:text="88888888888888888888888888888888888"
android:textColor="@color/holo_blue_light"
android:textSize="28dip" />
<TextView
android:id="@+id/textView_heading3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0.15"
android:gravity="center"
android:lines="1"
android:text="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
android:textColor="@color/holo_blue_light"
android:textSize="28dip" />
</RelativeLayout>
Works fine for some cases, but now look what happens if the textlength of the topmost View changes:
The Views aren't properly aligned any more, as only the upper View changed its width and therefore is centered again.
What I am asking is, is there a possibility to center a TextView, but only in steps of the width of one letter of the used monospace
-font
I think the best solution is to use a
TextView
for each char with a drawable that represent the two layers "8
" and "X
" as background.However, If you prefer, you can also use three horizontal
LinearLayout
for each layer in this way:So in onCreate() method you can retrieve all led chars in this way:
And then set the text you want with a method like this: