当我在NestedScrollView中添加RecyclerView时,我得到一个奇怪的滚动行为.
发生的事情是,只要滚动视图的行数多于屏幕中显示的行数,一旦启动活动,NestedScrollView就会从顶部开始偏移(图像1).如果滚动视图中的项目很少,以便可以一次显示它们,则不会发生这种情况(图2).
我使用的是支持库的23.2.0版.
图1:错误 - 从顶部偏移开始
图2:正确 - 回收者视图中的几个项目
我粘贴在我的布局代码下面:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title:"
style="@style/TextAppearance.AppCompat.Caption"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/bodyPadding"
style="@style/TextAppearance.AppCompat.Body1"
android:text="Neque porro quisquam est qui dolorem ipsum"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Subtitle:"
style="@style/TextAppearance.AppCompat.Caption"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TextAppearance.AppCompat.Body1"
android:padding="@dimen/bodyPadding"
android:text="Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:focusable="false" …
Run Code Online (Sandbox Code Playgroud) android android-support-library android-recyclerview android-nestedscrollview
我想知道是否有一种方法可以使提供程序的配置在整个应用程序中唯一,而不是在整个应用程序模块中唯一。
例如,我有一个模块“ core”,其中包含提供程序的定义。然后,我有了模块“ module1”和“ module2”,它们使用提供程序,但必须针对特定模块以特定方式对其进行配置。
我正在发生的事情是,在最后定义的模块中完成的配置将覆盖在应用程序中使用提供程序的所有其他模块中完成的配置。
我做了一个简单的例子来说明这一点:
var app = angular.module('app', ['module1','module2']);
angular.module('core',[])
.provider('movie', function () {
var version;
return {
setVersion: function (value) {
version = value;
},
$get: function () {
return {
title: 'The Matrix' + ' ' + version
}
}
}
});
angular.module('module1',['core'])
.config(function (movieProvider) {
movieProvider.setVersion('Reloaded');
})
.controller('ctrl1', function ($scope,movie) {
$scope.title = movie.title;
$scope.module = 'module1';
});
angular.module('module2',['core'])
.config(function (movieProvider) {
movieProvider.setVersion('Revolutions');
})
.controller('ctrl2', function ($scope,movie) {
$scope.title = movie.title;
$scope.module = 'module2'; …
Run Code Online (Sandbox Code Playgroud)