2011-12-29 14 views
0

私は現在、画面を3つのセクションに分割したいアンドロイドプロジェクトに取り組んでいます。スクロールセンターを持つ3つのコンポーネントのユーザーインターフェイス

最初のセクションは、画面の上部に位置移動しないタイトルであろう。 2番目のセクションはスクロール可能なメインコンテンツです 3番目のセクションは画面の下部に固定された2つのボタンです。

この設定では上部と下部には、画面上にとどまると、画面の唯一の中央部には、スクロール可能になります。私はトップとミドル細かい作業が、ボタンが示されることはありませんしている必要があり下部にこれを実行しようとしたいくつかの理由

、。以下は

私はあなたが提供することができます任意の助けのためにこの作業

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/start_eulaTitle" 
      android:textSize="15dp" 
      android:textStyle="bold" /> 
     <ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent"> 
      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/start_eula" /> 
     </ScrollView> 
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal"> 
     <Button android:id="@+id/start_btnAgree" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/button_agree" /> 
     </LinearLayout> 
    </LinearLayout> 

感謝を取得しようとするために使用したコードです。

答えて

0

A RelativeLayoutは、おそらくあなたが探しているものを達成するために行く方法です。ような何か:タイトルTextViewには、デフォルトで左最上部に座っている間

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

    <TextView 
     android:id="@+id/title_textview" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/start_eulaTitle" 
     android:textSize="15dp" 
     android:textStyle="bold" /> 

    <ScrollView 
     android:id="scrolling_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/button_layout" 
     android:layout_below="@+id/title_textview" > 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/start_eula" /> 
    </ScrollView> 

    <LinearLayout 
     android:id="@+id/button_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/start_btnAgree" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/button_agree" /> 

     <Button 
      android:id="@+id/start_btnAgree" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/button_agree" /> 
    </LinearLayout> 

</RelativeLayout> 

これは基本的には、常に画面の一番下に整列するボタンでのLinearLayoutを伝えます。スクロール可能な領域は、タイトルの下でボタンの上にある2つの間にとどまるように定義されています。

//編集:あなたは本当にルートとしてのLinearLayoutに固執したい場合は、次の操作を行い、潜在的可能性:

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

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/start_eulaTitle" 
     android:textSize="15dp" 
     android:textStyle="bold" /> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:text="@string/start_eula" /> 
    </ScrollView> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/start_btnAgree" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="@string/button_agree" 
      android:layout_weight="1"/> 

     <Button 
      android:id="@+id/start_btnAgree" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:text="@string/button_agree" 
      android:layout_weight="1" /> 
    </LinearLayout> 

</LinearLayout> 

魔法がScrollViewに1の重みを設定することによって起こります。これは、スクリーンから何も押さずに、できるだけビューを動的に伸ばします。

+0

ありがとう、素晴らしい作品です。 – Boardy

0

途中の要素と下の要素でandroid:layout_height="match_parent"(同じ数値の"fill_parent")を定義しているという問題があります。上から下にレイアウトすると、すべての利用可能なスペースがスクロールビューに表示されます。 android:layout_weightパラメータを調べるか、特定のlayout_heightを設定することができます。 15 dpなどがありますが、これらの絶対値は、Androidの場合(画面サイズや解像度が異なるため)はそれほど良いものではありません。

関連する問題