除广告外,我想要完整的屏幕滚动功能。但该列表视图显示了一个项目,如果高度是填充内容或包装内容。仅列出该场景中的视图滚动。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eeeeee">
<android.support.v7.widget.CardView
android:id="@+id/playback_error"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:animateLayoutChanges="true"
android:visibility="gone">
<TextView
android:id="@+id/error_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/error_message_background"
android:gravity="center"
android:paddingBottom="@dimen/error_vertical_padding"
android:paddingLeft="@dimen/error_horizontal_padding"
android:paddingRight="@dimen/error_horizontal_padding"
android:paddingTop="@dimen/error_vertical_padding"
android:textColor="@android:color/white"
android:textStyle="bold"
tools:text="Connectivity error!" />
</android.support.v7.widget.CardView>
<com.google.android.gms.ads.doubleclick.PublisherAdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="@string/verve_sdk_ad_unit_id"></com.google.android.gms.ads.doubleclick.PublisherAdView>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/adView">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:id="@+id/categoryImage"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/categoryTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1"
android:textColor="#000000"
android:textSize="20dp"
android:text="The Best Music"/>
<TextView
android:id="@+id/categoryDesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:textColor="#000000"
android:text="test description" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:background="@drawable/textlines"
android:ellipsize="end"
android:maxLines="1"
android:paddingBottom="20dp"
android:paddingLeft="10dp"
android:paddingTop="15dp"
android:text="Episodes / Tracks"
android:textColor="#ffffff"
android:textSize="30dp"
tools:background="#272727"
tools:text="Episodes / Tracks" />
</LinearLayout>
<!--<android.support.v7.widget.Toolbar-->
<!--android:id="@+id/toolbar"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="?attr/actionBarSize"-->
<!--app:layout_collapseMode="pin"-->
<!--app:popupTheme="@style/ThemeOverlay.AppCompat.Light"-->
<!--app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"/>-->
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
我尝试了填充内容/包装内容,但没有任何效果。
我在列表视图中有超过50个项目,但我也想用线性布局滚动屏幕。
感谢。
答案 0 :(得分:1)
尝试以下代码
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.rorkom.nikhil.scrolltest.ScrollingActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:id="@+id/categoryImage"
android:src="@drawable/ic_launcher_background"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/categoryTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLines="1"
android:textColor="#000000"
android:textSize="20dp"
android:text="The Best Music"/>
<TextView
android:id="@+id/somedesc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:textColor="#000000"
android:text="John Doe, his brothers, his sisters, his pets and his more than amazing band" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Add"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="100dp" />
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>