サイズ変更可能なアプリ ウィジェットがあります。画像の上と下に文字を入れたい 画像は可能な限り多くのスペースを確保し、テキストは画像の真上と真下に配置する必要があります。
これをxmlでのみ行いたいのですが、添付の画像に示されている両方の状況で機能するレイアウトがわかりません。
私の質問は、どの XML を使用してこの動作を実現できるかということです。
編集: イメージ ビューは、親コンテナー ビューよりも大きい場合があります。
サイズ変更可能なアプリ ウィジェットがあります。画像の上と下に文字を入れたい 画像は可能な限り多くのスペースを確保し、テキストは画像の真上と真下に配置する必要があります。
これをxmlでのみ行いたいのですが、添付の画像に示されている両方の状況で機能するレイアウトがわかりません。
私の質問は、どの XML を使用してこの動作を実現できるかということです。
編集: イメージ ビューは、親コンテナー ビューよりも大きい場合があります。
このようなもの:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="center"
android:layout_alignParentCenter="true"/>
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/imageview"
android:text="text 1"/>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/imageview"
android:text="text 2"/>
</RelativeLayout>
または、これは、レイアウトの重みを使用してサイズを制御します。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:weightSum="100"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_weight="10"
android:layout_height="0px"
android:text="text 1"/>
<ImageView
android:id="@+id/imageview"
android:layout_width="wrap_content"
android:layout_weight="80"
android:layout_height="0px"
android:scaleType="center"
android:layout_alignParentCenter="true"/>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_weight="10"
android:layout_height="0px"
android:text="text 2"/>
</LinearLayout>
ウェイト、画像の配置、画像の縮尺の種類を試して、思いどおりの画像を作成してください。