2016-02-25 16 views
5

Webサービスからコンテンツを動的にロードする必要があるページを持つアプリケーションを作成しました。 NestedScrollView内の線形レイアウトと一緒にスクロールできるlistviewが必要です。しかし、コンテンツがリストビューにロードされると、コンテンツは完全な高さに傷つきません。ListViewをNestedScrollView内に配置するには

ここに私のコードです。

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.myquestionth.myquestionth10.Profile2Activity" 
    tools:showIn="@layout/activity_profile2"> 

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

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

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="400dp" 
       android:background="#BBBBBB" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Media heading" 
       android:id="@+id/textView2" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis." 
       android:id="@+id/textView8" /> 

     </LinearLayout> 

     <ListView 
      android:id="@+id/listView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="#70bcf5" /> 

    </LinearLayout> 

</android.support.v4.widget.NestedScrollView> 

スクロールビューをネストすることはできません。 これは、私のレイアウトに合わせてGoogleの再生レビューページから欲しい例です。彼らはどのような方法を使用していますか?私が何か悪いことをしたら私に提案してください。どうもありがとう。ここで

enter image description here

私が欲しいものです。

enter image description here

+1

リストビューの高さを修正してください。または、最も良い方法はcoordinatorlayoutとrecyclerview.Refer [this](http://inthecheesefactory.com/blog/android-design-support-library-codelab/en)を使用することです。 –

答えて

4

まあ、私はあなたにその問題を解決するには2つの方法をお勧めします。ヘッダーは、hereと書かれているので、膨らませてください。

2)あなたはので、多分あなたも賢明な人々があなたのアダプターがどのように動作するかに似たループ内の行のビューを追加し、hereを示唆するように、のLinearLayoutとネストされた ScrollView内のListViewを交換してみてください、あなたはNestedScrollViewを使用することを述べました。

幸運を祈る!ロリポップの

1

代わりのリニアレイアウト以下のリストビューを追加し、ScrollViewの内側に、私はListViewコントロール内のすべてのものを置くことをお勧めします。

はいできます。

public class MyAdapter extends BaseAdapter { 
    // One view to Header 
    // One view to filter options ("most helpful first" and "Options") 
    // One view to comments 
    private final static int VIEW_HEADER = 0; 
    private final static int VIEW_OPTIONS = 1; 
    private final static int VIEW_COMMENTS = 2; 
    private final static int VIEW_TYPE_MAX = 3; 

    @Override 
    public int getViewTypeCount() { 
     // It will return 3 since I have 3 different types of VIEW 
     return VIEW_TYPE_MAX; 
    } 

    @Override 
    public int getItemViewType(int position) { 
     if (position == 0) 
      return VIEW_HEADER; 
     else if (position == 1) 
      return VIEW_OPTIONS; 
     else 
      return VIEW_COMMENTS; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     if (convertView == null) { 
      if(getItemViewType(position) == VIEW_HEADER) 
       // Inflate HEADER Layout 
      else if (getItemViewType(position) == VIEW_OPTIONS) 
       // Inflate Options Layout 
      else 
       // Inflate comments Layout 
     } 

     // Fill the view contents according to its type 
     .... 
     return convertView; 
    } 
} 

Androidはビューを再使用します。

は、アダプタ上の方法以下の(オーバーライド)を実装します。しかし、Androidは常に同じタイプのビューを再利用します。あなたのリストビューのヘッダをのLinearLayout作ってみる

1):

+0

ありがとうGuiherme私はこれを試みます。 – Marcus

+0

あなたも大歓迎です。アレックス・ペッパーの答えも試してみてください。元の回答者には – W0rmH0le

3

以降あなたはあなたがRecyclerViewを使用する必要がありますOSの旧バージョンとの下位互換性を必要とする場合、これは、このビュー ためのネストされたスクロールを有効または無効に

yourtListView.setNestedScrollingEnabled(true); 

を使用することができます。

+0

[クレジット](https://stackoverflow.com/a/35198484/4015799)の方が簡単です。 –