2012-03-20 21 views
0

どのようにレイアウトできますか?ヘッダーはスクロールしないでください。常に見えるようにしてください。スクロール可能なレイアウト

enter image description here

問題は、私はLinearLayoutScrollViewを入れしようとすると、Androidがエラーをスローです。

マークアップ:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       style="@style/baseLayout"> 
    <LinearLayout 
     style="@style/app_header" /> 
    <ScrollView 
     style="@style/fillParent"> 
     <!-- elements here --> 
    </ScrollView> 
</LinearLayout> 

スタイル:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <style name="app_theme" parent="android:Theme"> 
    </style> 

    <style name="fillParent"> 
     <item name="android:layout_width">fill_parent</item> 
     <item name="android:layout_height">fill_parent</item> 
    </style> 
    <style name="fullWidth"> 
     <item name="android:layout_width">fill_parent</item> 
     <item name="android:layout_height">wrap_content</item> 
    </style> 
    <style name="wrapContent"> 
     <item name="android:layout_width">wrap_content</item> 
     <item name="android:layout_height">wrap_content</item> 
    </style> 

    <style name="baseLayout" parent="fillParent"> 
     <item name="android:orientation">vertical</item> 
     <item name="android:background">@drawable/app_bg</item> 
    </style> 

    <style name="app_header" parent="fullWidth"> 
     <item name="android:background">@drawable/header_bg</item> 
    </style> 
</resources> 
+0

正確なエラーを表示できますか? – prolink007

答えて

2

次のコードは、あなたのコードを投稿して私たちはあなたが間違っているかもしれないものを見てみましょうことができ、私の作品?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
    <TextView android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="TITLE BAR"/> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

ソリューション

問題は忍者がScrollViewに1人の以上の直接の子供を持っていたことでした。

+0

編集を見てください。 –

+0

私は今見ています。追加情報をありがとう。 – prolink007

+0

'LinearLayout style =" @ style/app_header "/>'の目的は何ですか?今は空で不要なようです。その代わりに 'TextView'を入れて、何が起こるか見ることができます。 'TextView'の背景を変更することができます。 – prolink007

1

スクロールビューの横にリニアレイアウトを配置するとエラーが発生するのは正常ではありません。 下記のスニペットをコード内で試してください。

<?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="match_parent" 
    android:layout_height="wrap_content" 
    android:text="TITLE BAR"/> 

    <ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:fillViewport="true" 
    android:orientation="vertical" > 

     <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" > 
     . 
     . 
     </LinearLayout> 

    </ScrollView> 

</LinearLayout> 

これが役立ちます。あなたのマークアップで

+0

DotNET Ninjaは、 'LinearLayout'の中に' ScrollView'を置くことを試みていると言いました。また、私は何をしたのですか? lol – prolink007

+0

あなたの場合、アンドロイドスクロールビューには1人の子供しか持たないため、あなたの場合、スクロールビュー内にリニアレイアウトを設定する必要があります。したがって、すべてのスクロール可能なコンテンツは内側の線形レイアウトの内側にあります。 –

+0

はい、ただタグですが、あなたに怒られたらごめんなさい。 –

1

.... 
<ScrollView 
     style="@style/fillParent"> 
     <!-- elements here --> 
</ScrollView> 
... 

「ここの要素」 - ScrollViewは、(例えば、レイアウトの)唯一の直接の子をホストすることができますので、複数のは、あなたは、エラーになります場合。

関連する問題