1

私はアンドロイド開発に不慣れで、レイアウト設計に関して疑問があります。次のコードがありますが、思い通りに動作しません。画像ビューに私が撮った写真を表示し、その下にユーザーがデータを入力するためのテキストボックスを表示したいと思います。ただし、現時点では、画像が画面全体を占めており、テキスト ボックスを見つけることができませんでした。アドバイスよろしくお願いします。ありがとう!

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/linear">

    <ImageView android:id="@+id/imageView1"
        android:layout_width="fill_parent" android:layout_height="fill_parent" 
        android:contentDescription="@string/desc"/>

    <EditText
        android:id="@+id/editTextSimple1"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
        <requestFocus />
    </EditText>

</LinearLayout>
4

4 に答える 4

1

LinearLayout の代わりに RelativeLayout を使用し、xml コードの代わりに以下の xml コードを使用すると、問題が解決します。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/editTextSimple1"
        android:contentDescription="desc" />

    <EditText
        android:id="@+id/editTextSimple1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

        <requestFocus />
    </EditText>

</RelativeLayout>
于 2012-12-12T09:55:18.277 に答える
1

問題は

android:layout_height ="fill _parent"

これにより、親スペース全体、つまり画面全体を占有します

高さをdp、pxなどの特定の値に設定するか、使用します

android:layout_height="wrap_content"

ビューが画面に収まるほど小さい場合

于 2012-12-12T09:45:44.600 に答える
1

ImageView レイアウトの高さを次のように変更しますlayout_height="wrap_content"
。layout_height="fill_parent" を使用すると、画像がすべてのスペースを占有します。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:id="@+id/linear">

    <ImageView android:id="@+id/imageView1"
        android:layout_width="fill_parent" 
android:layout_height="wrap_content"  
        android:contentDescription="@string/desc"/>

    <EditText
        android:id="@+id/editTextSimple1"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
        <requestFocus />
    </EditText>

</LinearLayout>
于 2012-12-12T09:41:21.683 に答える
0
<ImageView android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:contentDescription="@string/desc"/>

このように ImageView に重みを追加します。それが動作します。

于 2012-12-12T09:44:43.303 に答える