2013-05-02 14 views
6

ListViewScrollViewを一緒に使用しないでください。しかし、私は現在、ユーザープロファイル用の領域と作成したミックスのリストを含む8トラックのプロファイルページ(下の画像に示すような)のような非常に単純なパターンに固執しています。基本的に、ユーザーはそのページを下にスクロールできるだけです。つまり、プロファイルの部分が画面の上に徐々に表示され、同時に次のリストもスクロールされます。Android - ListViewスクロール可能なLinearLayoutを作成する

enter image description here

ただし、現時点では、ここで私のスケッチと同じようにListViewLinearLayoutに含めることができます。この設計では

enter image description here

プロファイル領域が吸う同じ場所、にとどまる一方で、私は、リストを下にスクロールすることができます。だから私は、リストだけでなく、ページ全体をスクロール可能にする考えを探しています。助けてくれてありがとう。

EDITED:誤解を招くような質問は申し訳ありません。私の問題は、タブの内容がちょうどListViewではないため、さらに複雑になります - 一部のタブには、代わりにLinearLayoutまたはGridViewが含まれています。ここでもまた達成したいのは、ページ全体をスクロール可能にすることですが、タブの内容がListViewまたはGridViewである場合、これらのビューは折りたたまれ、より重要なことになります。これはデザインルールに反するためです。

答えて

1

私はこれが遅いと知っていますが、私は8トラックの現在の開発者です。あなたが上に示した(古い)2.xアプリは書き直されていますが、私は古い開発者がプロ​​フィールページのために何をしたのかを示すことができます。

これに入る前に、これはこれを実行する最善の方法ではないが、8トラックのアプリ(2.x)は古いと言わなければならない。

コードに戻る... ProfileActivityには、ProfileFragmentが含まれています。

あなたがフォローボタン(とプロフィール画像)を参照して、メインレイアウトはこれです:あなたはそれが3との定期的なレイアウトだ見ることができるように

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

    <!-- Image, name, location --> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:padding="10dip" > 

     <com.gdub.widget.ImageViewClickable 
      android:id="@+id/dj_avatar" 
      android:layout_width="110dip" 
      android:layout_height="110dip" 
      android:layout_marginRight="10dip" 
      android:background="@drawable/default_avatar_max200" 
      android:scaleType="centerCrop" /> 

     <com.gdub.widget.CollapsingTextView 
      android:id="@+id/dj_location" 
      style="@style/mix.counts" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dip" 
      android:layout_toRightOf="@id/dj_avatar" /> 

     <ViewSwitcher 
      android:id="@+id/profile_action_btn" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/dj_location" 
      android:layout_toRightOf="@id/dj_avatar" > 

      <Button 
       android:id="@+id/follow_btn" 
       style="@style/white_button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/follow" /> 

      <Button 
       android:id="@+id/edit_profile_btn" 
       style="@style/white_button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/edit_profile" /> 
     </ViewSwitcher> 
    </RelativeLayout> 

    <TextView 
     android:id="@+id/dj_bio" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="-25dip" 
     android:gravity="left|center_vertical" 
     android:lineSpacingExtra="2dip" 
     android:paddingLeft="10dip" 
     android:paddingRight="10dip" 
     android:textColor="@color/default_text" 
     android:textSize="15sp" /> 

    <include 
     android:id="@+id/profile_tabs" 
     layout="@layout/profile_tabs" /> 

</LinearLayout> 

そしてprofile_tabs ...

<?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="wrap_content" 
    android:visibility="gone" 
    android:orientation="horizontal"> 

    <include 
     android:id="@+id/profile_mixes_button" 
     layout="@layout/profile_tab" /> 

    <include 
     android:id="@+id/profile_followers_button" 
     layout="@layout/profile_tab" /> 

    <include 
     android:id="@+id/profile_following_button" 
     layout="@layout/profile_tab" /> 

</LinearLayout> 

ボタンを "シミュレート"するボタン。タブの

内容もViewSwitcherによって決定される:

<?xml version="1.0" encoding="utf-8"?> 
<ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/profile_view_switcher" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:inAnimation="@anim/fade_in_300" 
       android:outAnimation="@anim/fade_out_300" 
       android:background="@color/white"> 

<include 
    android:id="@+id/profile_loading" 
    layout="@layout/loading_view_full" /> 

<ListView 
    android:id="@+id/profile_content_list" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:cacheColorHint="#00000000" 
    android:divider="@null" 
    android:dividerHeight="0dip" 
    android:fadingEdge="none" /> 

</ViewSwitcher> 

ロードホイールを示し、その後、リストビューに切り替えています。他のスクロール可能なViewGroupはありません。

それは基本的にそれです。

ここで、全機能をスクロールするには、カスタムアダプターを使用し、ヘッダーとして上記のレイアウトを設定する必要があります(または、少なくとも、賢明な方法でアダプターのgetItemTypeを使用する必要があります)。そうすれば、画面全体がリストになります(リストにはすべての最適化があります)。

私たち(ab)はdevの下の新しい8トラックのアプリでこれを使用します。 ;)

+1

著者からの回答があることは素晴らしいことです!これはとても賢明で、本当に感謝しています。私はプロジェクトを終えましたが(ヘッダー部分をあきらめて)、これは将来私にとって役立つと確信しています。 –

+0

あなたは大歓迎です! :) –

1

リストビューで次の項目を使用してください。

listview.addHeaderView(v); 

また、リストビューでsetAdapter()を呼び出す前に、このメソッドを呼び出す必要があります。

には、ユーザーの詳細とタブがあり、ヘッダーとしてリストに追加する線形レイアウトが含まれています。

+0

私はこのことについて一度も学ばなかったので残念です。私を啓発してくれてありがとう。しかし残念ながら、これは私の必要性に合っていません。なぜなら、実際には私のタブの1つにListViewが含まれていて、他にGridViewとLinearViewが含まれているので、タブをヘッダーとして追加するのではなく、リストビュー。 –

0

プロファイルとタブをlistviewのヘッダーにしてから、タブを押したときにリストビューの内容を更新できます。あなたがスクロールするときにタブが見えないようにするかどうかは分かりません。

+0

これは、すべてのタブにリストビューが含まれているわけではないので、わかりやすいものです。もし、最初のタブに 'LinearLayout'があり、他の2つだけが' ListView'を持っていたらどうしたらいいですか? –

0

UIガイドラインとベストプラクティスによれば、Scrollview内でScrollableコンテンツを使用しないことをお勧めします。そうすることで、Scrollableコンテンツのスクロールを防ぐことができます。

あなたが2つのスクロールビューを入れたら、アンドロイドはちょうどどのスクロールビューがタッチされたのか混乱します。時にはタッチイベントを配信できなくなることがあります。

ただし、スクロール機能を実現したい場合は、特定のビューのonTouchイベントを使用してスクロール機能を管理できます。それに応じてレイアウトを設計する必要があります。

しかし、そのようなレイアウトを作成する必要がある場合でも、これを試してみてください...

<ScrollView android:id=”@+id/parent_scroll” 
     android:layout_width=”fill_parent” 
     android:layout_height=”wrap_content” 
     android:layout_weight=”1″ 
     android:background=”@drawable/dotted_bg” 
     android:focusableInTouchMode=”false”> 
        <LinearLayout /> 
        <LinearLayout /> 
        <LinearLayout > 
        <ScrollView android:id=”@+id/child_scroll” 
        android:layout_width=”fill_parent” 
        android:layout_height=”fill_parent” 
        android:background=”@drawable/text_box_bg”> 
       <TextView android:id=”@+id/text_description” 
        android:layout_width=”fill_parent” 
        android:layout_height=”fill_parent” 
        android:textColor=”@color/gray” 
        android:textSize=”12dip” 
        android:padding=”5dip” 
        android:scrollbars=”vertical”/> 
       <!–ScrollView> 
       </LinearLayout> 

ステップ1:scrollviewの両方に一意のIDを提供します。

ステップ2:あなたのアクティビティでその2つのスクロールビューの参照を取得します。

parentScroll=(ScrollView)findViewById(R.id.parent_scroll); 
    childScroll=(ScrollView)findViewById(R.id.child_scroll); 

ステップ3:今の両方にタッチリスナーを設定します。

parentScroll.setOnTouchListener(new View.OnTouchListener() { 
      public boolean onTouch(View v, MotionEvent event) { 
       Log.v(TAG,”PARENT TOUCH”); 
    findViewById(R.id.child_scroll).getParent().requestDisallowInterceptTouchEvent(false); 
       return false; 
      } 
     }); 
     childScroll.setOnTouchListener(new View.OnTouchListener() { 
      public boolean onTouch(View v, MotionEvent event) 
      { 
       Log.v(TAG,”CHILD TOUCH”); 
            // Disallow the touch request for parent scroll on touch of child view 
       v.getParent().requestDisallowInterceptTouchEvent(true); 
       return false; 
      } 
     }); 

私はそれはあなたを助けることを願っています。

+0

詳細な回答ありがとうございますが、私はあなたが私の質問を誤解していると思います(タイトルが誤解を招く可能性がありますので、それは私のせいです)。私が達成したいのは、ページの一部だけでなく、ページ全体をスクロールできることです。親スクロールを無効にして子をスクロール可能にすることは、直線レイアウト内にリストビューを追加するようなものです。 –

+0

あなたは正確に何を達成したいですか? ListView&Wholeレイアウトでスクロール可能にしますか? – GrIsHu

+0

私はちょうど私の質問とタイトルを編集したので、それをチェックしてください。また、より良いデザインの提案があれば、さらに感謝します。 –

関連する問題