1

EditText次の3つのルールに従う常に存在するレイアウトを作成するにはどうすればよいですか。

EditTextビュー:

  1. 画像が存在しない場合は親全体を塗りつぶします(View.GONEこの場合、実行時に可視性がに設定されます)。
  2. 画像の高さが幅よりも高い場合は、親の高さの50%を塗りつぶします。
  3. 画像の幅が高さよりも広い場合は、親の残りの部分を塗りつぶします。

もちろん、画像は、アスペクト比を維持しながら、親の長方形の一番下の50%の内側に収まるように引き伸ばされます。

ここに画像の説明を入力してください

4

3 に答える 3

0

これを試して:

<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>
于 2012-10-08T00:21:22.347 に答える
0

これは単一のxmlレイアウトで実行できるとは思いませんが、簡単な方法は、画像の存在とアスペクト比に応じて膨らませる複数のxmlレイアウトファイルを用意することです。

于 2012-10-08T01:01:23.533 に答える
0

これが私がそれをした方法です。結果のレイアウトは次のようになります。

ここに画像の説明を入力してください ここに画像の説明を入力してください

ここに画像の説明を入力してください

<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>
于 2012-10-08T16:29:45.803 に答える