偽のLCDディスプレイを作成しようとしています。テキストビューは、固定幅の文字の幅で中央に配置します
それはLCDの外観を偽造、いくつかのデータを示すいくつかの通常のテキスト、および背景の存在している必要があります:
を私は互いの上に3 TextViewsを合わせ、このXMLを書きました。
<?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>
は、いくつかのケースのために正常に動作しますが、今一番上の表示が変わるのtextlengthがあれば何が起こるか見て:としてだけ上位表示が変更
ビューが正しく、もはや整列されていないそのしたがって、再度中心合わせされます。
私が求めています何、はTextViewのをセンタリングする可能性があるが、唯一の使用monospace
-font
ありがとうございます。ただし、そのコードでは、テキストは左揃えになります。しかし、それを中心にすることは大したことではありません。この解決策の欠点は、数字の桁数がそれ以上変わることがなく、画面サイズを犠牲にすることができないことです。もし私がそれを使うことができれば、多分いくつかの修正を加えて、私はそれを調べるでしょう。 – msal
@ walla:画面サイズに合わせて、実行時に 'TextView'sを' LinearLayout'に追加することができます。 もう1つの解決策は、Androidが望むように、異なる桁数の異なるXMLレイアウトを持つことです[複数のスクリーンをサポート](http://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts):たとえば7インチのタブレットで5桁、10インチのタブレットで8桁の 'res \ layout-sw720dp \ lcd_layout.xml'を持つ' res \ layout-sw600dp \ lcd_layout.xml'を持っています。 –
良い点。私はそれを考慮に入れます。 – msal