EditText
次の3つのルールに従う常に存在するレイアウトを作成するにはどうすればよいですか。
EditText
ビュー:
- 画像が存在しない場合は親全体を塗りつぶします(
View.GONE
この場合、実行時に可視性がに設定されます)。 - 画像の高さが幅よりも高い場合は、親の高さの50%を塗りつぶします。
- 画像の幅が高さよりも広い場合は、親の残りの部分を塗りつぶします。
もちろん、画像は、アスペクト比を維持しながら、親の長方形の一番下の50%の内側に収まるように引き伸ばされます。
EditText
次の3つのルールに従う常に存在するレイアウトを作成するにはどうすればよいですか。
EditText
ビュー:
View.GONE
この場合、実行時に可視性がに設定されます)。もちろん、画像は、アスペクト比を維持しながら、親の長方形の一番下の50%の内側に収まるように引き伸ばされます。
これを試して:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
</EditText>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:src="@drawable/ic_launcher"/>
</LinearLayout>
これは単一のxmlレイアウトで実行できるとは思いませんが、簡単な方法は、画像の存在とアスペクト比に応じて膨らませる複数のxmlレイアウトファイルを用意することです。
これが私がそれをした方法です。結果のレイアウトは次のようになります。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="blah" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="gone"
android:src="@drawable/photo1" />
</LinearLayout>