ImageView
を使って、派手な方法でメッセージを表示したいと思います。
にテキストを追加するにはどうすればよいImageView
ですか?
あなたにテキストを追加するには、ImageView
これを行うことができます:
<RelativeLayout> // Only works inside a RelativeLayout
<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>
また、TextView を使用して、背景画像を で必要なものに設定することもできますImageView
。さらにImageView
、ボタンとして使用している場合は、クリック可能に設定できます
TextView
上にテキストがある画像を表示するの基本的なコードを次に示します。
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/your_image"
android:text="your text here" />
単一のビューでテキストと画像を使用するための最良のオプションは、これを試してください:
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableBottom="@drawable/ic_launcher"
android:text="TextView" />
TextView で drawalbeLeft/Right/Bottom/Top を使用して、それぞれの位置に画像をレンダリングします。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/image"
android:text="@strings/text"
/>
キャンバスにテキストを直接描画するには、次の操作を行います。
myImageView
コンストラクターでメンバー Paint オブジェクトを作成する
Paint mTextPaint = new Paint();
メソッドで使用canvas.drawText
します。myImageView.onDraw()
canvas.drawText("My fancy text", xpos, ypos, mTextPaint);
Paint および Canvas クラスのドキュメントを調べて、派手な効果を追加します。
FrameLayout を使用すると、イメージ ビューの上にテキストを配置できます。フレーム レイアウトは、imageView と textView の両方を保持します。
それだけでは不十分で、「描画」テキストのようなもっと凝ったものが必要な場合は、キャンバスにテキストを描画する必要があります。サンプルは次のとおりです: RTL テキスト (アラビア語) をビットマップに描画し、適切に並べ替える方法
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="30" >
<ImageButton
android:id="@+id/imgbtnUploadPendingPods"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/hello_world"
android:src="@drawable/upload_icon" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="30dp"
android:text="@string/pendingpods"
android:textAppearance="?android:attr/textAppearanceSmall" />
</FrameLayout>