几乎每个人都建议我不要在nestedScrollView中使用ListView。但是我需要使用nestedScrollView来实现CollapsingToolbar行为。我也不能使用RecyclerView,因为我建议使用它Fabric twitter套件,它不支持RecyclerView(截至目前)。myListview.setNestedScrollingEnabled(true);
有效,但只能从android 5.0开始如何实现这一点。
这是我的代码
aspirant_profile.xml
`<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
tools:ignore="MissingPrefix"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.esir.jualeader.aspirant.AspirantProfile">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_height="250dp"
android:minHeight="250dp"
android:layout_width="match_parent"
style="@style/expandedappbar"
>
<!--style="@style/CustomActionBarTitleBase"-->
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:toolbarId="@+id/toolbar"
android:id="@+id/collapsing_toolbar"
app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed"
app:contentScrim="?attr/colorPrimary"
>
<ImageView
android:id="@+id/app_bar_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/album10"
app:layout_collapseMode="parallax"
android:scaleType="centerCrop" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:src="@android:drawable/ic_input_add"
android:layout_marginRight="16dp"
android:clickable="true"
app:fabSize="mini" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
<LinearLayout
android:theme="@android:style/ThemeOverlay.Material.Light"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:targetApi="lollipop"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/aspirant_pp_and_aspirant_name"
>
<com.pkmmte.view.CircularImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/album1"
app:border="true"
app:border_color="#EEEEEE"
app:border_width="4dp"
app:shadow="true" />
<LinearLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/aspirant_name_and_aspirant_docket"
android:padding="5dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/aspirant_name_at_profile"
android:text="Isaiah"
android:textSize="25sp"
style="@style/TextViewHeadline"
fontPath="fonts/Roboto-Bold.ttf"
/>
<!-- style="@style/TextViewHeadline"-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/aspirant_docket_at_profile"
android:text="Presidency"
style="@style/TextViewSubhead"
fontPath="fonts/Roboto-Medium.ttf"
/>
<!-- style="@style/TextViewTitle"-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
>
<!--android:theme="@style/TextViewButton"-->
<Button
android:theme="@style/myBut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="VOTE UP"
android:textColor="@color/white"
android:id="@+id/button_vote_up"
android:enabled="true"
android:shadowColor="@color/colorPrimaryDark"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
fontPath="fonts/Roboto-Medium.ttf"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Vote For Isaiah"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textViewNote"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
style="@style/TextViewSubhead"
fontPath="fonts/Roboto-Regular.ttf"
/>
<!--style="@style/TextViewSubhead"-->
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
/>
<!-- Contain Number Of Votes And Political Party-->
<RelativeLayout
style="@android:style/ThemeOverlay.Material.Light"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/relativeLayout"
android:layout_margin="5dp"
>
<RelativeLayout
android:id="@+id/political_party_circle"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/votes_bg"
android:layout_gravity="center"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Juele"
android:gravity="center"
android:id="@+id/political_party_name"
android:layout_centerInParent="true"
style="@style/TextViewCaption"
fontPath="fonts/Roboto-Regular.ttf"
android:textSize="13sp"
/>
<!--style="@style/TextViewCaption"-->
</RelativeLayout>
<!-- Political Party -->
<TextView
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/political_party_name_title"
android:text="Political Party"
android:layout_below="@+id/political_party_circle"
android:layout_centerInParent="true"
style="@style/TextViewSubhead"
/>
<!--style="@style/TextViewSubhead"-->
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_margin="5dp"
>
<!-- Number Of Votes -->
<RelativeLayout
android:id="@+id/votes_circle"
android:layout_width="70dp"
android:layout_height="70dp"
android:background="@drawable/votes_bg"
android:layout_gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5,239,888"
android:gravity="center"
android:id="@+id/votes"
android:layout_centerInParent="true"
style="@style/TextViewCaption"
/>
<!--style="@style/TextViewCaption"-->
</RelativeLayout>
<TextView
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Votes"
android:id="@+id/votes_title"
android:layout_below="@+id/votes_circle"
android:layout_centerInParent="true"
style="@style/TextViewSubhead"
/>
<!-- style="@style/TextViewSubhead"-->
</RelativeLayout>
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
/>
<!-- Add Layout For The Manifesto-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Manifesto"
android:paddingBottom="5dp"
android:textSize="24sp"
style="@style/TextViewHeadline"
/>
<!--style="@style/TextViewHeadline"-->
<at.blogc.android.views.ExpandableTextView
android:id="@+id/expandableTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/longtxt"
android:maxLines="3"
android:ellipsize="end"
app:animation_duration="1000"
android:textSize="14sp"
style="@style/TextViewBody1"
fontPath="fonts/Roboto-Regular.ttf"
/>
<!--style="@style/TextViewBody1"-->
<Button
android:id="@+id/read_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Read More"
android:textColor="@color/colorAccent"
android:theme="@style/MyButton"
android:layout_gravity="center"
style="@style/Widget.AppCompat.Button.Borderless"/>
<!-- Add A ViewPager With ImageView-->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Photos"
android:id="@+id/photos_text"
android:textColor="@color/colorAccent"
android:layout_gravity="center"
/>
<include layout="@layout/aspirants_images"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Tweets"
android:id="@+id/tweets_text"
android:textColor="@color/colorAccent"
android:layout_gravity="center"
/>
<!-- LAYOUT WITH THE ListView-->
<include layout="@layout/aspirant_tweets"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>`
aspirant_tweets.xml
`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="500dp"
tools:showIn="@layout/aspirant_profile"
android:id="@+id/aspirant_tweet_layout">
<TextView android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Loading Tweets..."
android:gravity="center_horizontal|center_vertical"/>
<ListView
android:id="@+id/aspirant_tweets_list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#e1e8ed"
android:dividerHeight="1dp"
android:drawSelectorOnTop="false"
/>
</LinearLayout>`
提前致谢。