2010-12-01 7 views
2

画面よりも大きいユーザーフォームが必要です。レイアウトは、固定された「タイトル領域」、フォーム(可能であればスクロールビュー内)、およびボトムのボタンで構成されます。 3つのレイアウトを作成し、中間のレイアウトは垂直方向のLinearLayoutを持つScrollViewです。残念ながら、フォームはボタンを画面から押し出すのですか?Android SDKでスクロールするフォームをレイアウトするにはどうすればよいですか?

これを行う簡単な例はありますか?

私はListViewを使うことができますが、私のScrollViewは管理しやすいと思います。固定ヘッダとフッタを持つ、そして何中央を埋める(あなたのケースでは、ScrollView) - ここに私のレイアウトは、私が正しく理解していれば、これはかなり一般的に育てていますものです...

<?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" 
    > 

    <!-- Title Area on top --> 
    <LinearLayout 
    android:id="@+id/layout_form" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    > 
    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
    > 
     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="0dip" 
      android:layout_marginBottom="0dip" 
      android:paddingTop="20dip" 
      android:paddingBottom="20dip" 
      android:paddingLeft="5dip" 
      android:paddingRight="10dip" 
      android:src="@drawable/logo" 
      android:layout_gravity="center" 
      android:layout_weight="1" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="2" 
      android:layout_marginTop="0dip" 
      android:layout_marginBottom="0dip" 
      android:layout_marginLeft="4dip" 
      android:layout_marginRight="4dip" 
      android:text="@string/title_create" 
      /> 
    </LinearLayout> 

    <!-- Form entry on top --> 

     <ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:fillViewport="true" 
      android:clipChildren="true" 
      > 
      <LinearLayout 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
      > 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginLeft="8dip" 
      android:layout_marginRight="8dip" 
      android:text="@string/label_field_one" 
      /> 
     <EditText 
      android:id="@+id/edit_field_one" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:layout_marginLeft="10dip" 
      android:layout_marginRight="10dip" 
      android:hint="@string/hint_field_one" 
      /> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginLeft="8dip" 
      android:layout_marginRight="8dip" 
      android:text="@string/label_field_two" 
      /> 
     <EditText 
      android:id="@+id/edit_field_two" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:singleLine="true" 
      android:layout_marginLeft="10dip" 
      android:layout_marginRight="10dip" 
      android:hint="@string/hint_field_two" 
      /> 

      <!-- Repeat label-text and edit-text until done ... --> 

      </LinearLayout> 
      </ScrollView> 


    <!-- "spring" between form and wizard buttons. --> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
    /> 

    <LinearLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="left" 
     android:layout_weight="2" 
     > 
     <Button 
      android:id="@+id/btn_submit" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="right" 
      android:layout_weight="1" 
      android:text="@string/button_submit" 
     /> 
    </LinearLayout> 
     </LinearLayout> 


</LinearLayout> 

答えて

3

です。それはあなたが探しているものですか?基本的に、あなたは、ヘッダーを定義し、それを一定の高さ(この場合はwrap_content)を得て、親の先頭に整列するように設定し

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    > 
    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     > 
     //.....stuff here 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/footer" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     > 
     //.....stuff here 
    </LinearLayout> 
    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_above="@id/footer" 
     android:layout_below="@id/header" 
     > 
     //......stuff here 
    </ScrollView> 
</RelativeLayout> 

:その場合は、以下のようなものを試してみたいと思います(RelativeLayout)です。次に、フッターを親の一番下に合わせて同様に行います。あなたの状況のた​​めに、フッターの代わりにLinearLayoutの代わりにボタンを使うこともできますし、ボタンをLinearLayoutの中に置くこともできます。余分なLinearLayoutを使わずにレイアウトを膨張させるのはおそらく少し速いでしょう。しかし、とにかく、次に、フォーム、スクロール領域を定義します。高さをfill_parentに設定し、フッターの上とヘッダーの下になるように指示します。これにより、ヘッダーとフッターの間の残りのスペースをすべて占有します。

+0

はい、私は、途中でスクロールするフォームでヘッダー(教育)/フッター(実行可能)を探しています。私は今これをコード化し、これが私のレイアウトのために働くかどうかを知らせます。 – mobibob

+0

それはうまくいった。しかし、今では、入力メソッドは私が望むように振る舞いません(異なる問題とおそらく新しい質問)。 NEXTボタンが表示されず、データを入力するときにタッチすると不動産が混雑します。 – mobibob

+0

不動産の問題は画面サイズの制限に過ぎません。(Facebookのアプリはこれの素晴らしい(ひどい?)例ですが)、キーボードをフルスクリーンで開くか、コンテンツをEditTextは残りの領域内にあります。また、EditTextボックスでキーボードの「次へ」ボタンを指定する必要があると指定する必要があると思いますが、残念ながら私はあまりそれを自分でやっていないので、別の質問を投げたいかもしれませんそれのために。 – kcoppock

関連する問題