在正常的recyclerview中,最新的项目都在顶部,如果您将项目添加到recyclerview中,它会将现有项目向下推,新项目将位于顶部位置.
在reverseLayout recyclerview中,最新的项目都在底部,如果您将项目添加到recyclerview中,则会在底部添加.这种布局对于评论提要非常有用,您希望最新评论位于底部.
例如,当您评论朋友的状态时,Facebook评论供稿就是一个很好的例子.您可以看到评论都有时间在底部发布,时间从上到下从12小时减少到10小时:
reverseLayout很容易设置,我使用这段代码完成了它:
mLayoutManager = new LinearLayoutManager(this);
mLayoutManager.setReverseLayout(true);
mLayoutManager.setStackFromEnd(true);
Run Code Online (Sandbox Code Playgroud)
然而,我正在努力附加一个反向无限滚动监听器.我使用下面的维伦的代码,我的问题了一段时间后(在底部带有进度添加项目到无尽的滚动RecyclerView),然后修改它,使它的onLoadMoreListener只会激活自己当它向下,而不是向上滚动.您想要向上滚动到较旧的评论:
if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
//if you add on addOnScrollListener, it will cause the scroll listener to be called twice each time you reset your adapter
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
int firstVisibleItem;
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
final int currentFirstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition();
totalItemCount = linearLayoutManager.getItemCount();
lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
if(lastVisibleItem > firstVisibleItem)
{
Log.i("SCROLLING …Run Code Online (Sandbox Code Playgroud) 我对Android很新,我正在谷歌网站上探索示例代码.我目前的代码是SwipeRefreshLayout:http://developer.android.com/samples/SwipeRefreshLayoutBasic/index.html
在代码中,我们看到正在为列表视图执行SwipeRefreshLayout,换句话说,如果向下拖动列表视图,则会触发该方法并且listview将自行刷新.
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
Run Code Online (Sandbox Code Playgroud)
让我感到困惑的是,当您向下拖动时,进度动画栏的代码中没有布局显示在列表视图的顶部.你认为SwipeRefreshLayout在你向下拖动时自动生成一个进度动画条而不需要用户在xml中为它指定任何布局吗?
例如,如果想要在进度动画栏的两端放置填充,以便在刷新时动画不会触摸屏幕的末端,那么如何进行操作?
该https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html并没有真正说什么.
我编写了以下代码来测试同步RestTemplate和AsyncRestTemplate的性能.我只是在POSTMAN上手动运行了几次.
我们只是将10个引用传递给GET调用,以便我们可以返回10个链接:
RestTemplate - 同步并在2806ms返回:
ArrayList<String> references = new ArrayList<>();
ArrayList<String> links = new ArrayList<>();
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
for (int i = 0; i < 10; i++) {
ResponseEntity<String> resource = restTemplate.getForEntity(references.get(i), String.class);
links.add(resource.getBody().toString());
}
Run Code Online (Sandbox Code Playgroud)
RestTemplate - 异步并返回2794ms:
//Creating a synchronizedList so that when the async resttemplate returns, there will be no concurrency issues
List<String> links = Collections.synchronizedList(new ArrayList<String>());
//CustomClientHttpRequestFactory just extends SimpleClientHttpRequestFactory but disables automatic redirects in SimpleClientHttpRequestFactory
CustomClientHttpRequestFactory customClientHttpRequestFactory = new CustomClientHttpRequestFactory();
//Setting the …Run Code Online (Sandbox Code Playgroud) 有没有办法让小吃吧在展示时向上推动视图?
目前,当显示小吃栏时,它覆盖在下面的视图上,因此它看起来像按钮的一半被切断但我希望它几乎"adjustPan"类似于软键盘在屏幕上显示时的工作方式.
有谁知道实现这个的任何技巧?
我正在尝试做一些非常简单的事情.
我希望FAB只显示在我的TabLayout中的一个选项卡上,并在导航到另一个选项卡时隐藏.因此,例如,一个选项卡允许您在FAB中添加新项目,但下一个选项卡不允许您添加项目.
我遵循了"典型的"XML设计布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
xmlns:tools="http://schemas.android.com/tools"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<LinearLayout
android:id="@+id/search_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal">
<EditText
android:id="@+id/search_view"
android:layout_width="0dp"
android:layout_height="?attr/actionBarSize"
android:layout_weight="1"
android:background="@android:color/transparent"
android:gravity="center_vertical"
android:hint="Search"
android:imeOptions="actionSearch"
android:inputType="text"
android:maxLines="1"
android:paddingLeft="2dp"
android:singleLine="true"
android:textColor="#ffffff"
android:textColorHint="#b3ffffff" />
<ImageView
android:id="@+id/search_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:src="@drawable/ic_action_cancel" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:tabMode="scrollable"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="com.example.simon.behaviours.PatchedScrollingViewBehavior"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
app:borderWidth="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_action_new"
android:layout_margin="16dp"
android:layout_gravity="bottom|right" …Run Code Online (Sandbox Code Playgroud) 我阅读了关于这个主题的所有主题,并且使用genymotion设置查尔斯的说明都是一样的:
http://rexstjohn.com/using-genymotion-charles-proxy/
In your Genymotion Android emulator…
Settings -> Wifi -> Press and hold your active network
Select “Modify Network”
Select “Show Advanced Options”
Select “Proxy Settings -> Manual”
Set your Proxy to: 10.0.3.2 (Genymotion’s special code for the local workstation)
Set your Port to: 8888
Press Save
Run Code Online (Sandbox Code Playgroud)
我的设置是:
我不确定说明是否旧,但我遇到的问题是从我的genymotion模拟器流出的流量记录在Charles Proxy中,但它没有到达我的localhost服务器.我在我的服务器和我的应用程序之间没有使用任何SSL加密.
这是我在genymotion wifi屏幕内的设置:
这就是我的Charles Proxy的样子 - 你可以看到它是"连接到远程主机".它永远连接,然后最终在我的Android应用程序端给我一个503错误,没有返回任何内容:
如果我关闭Charles Proxy,应用程序连接我的localhost服务器没有问题,所有调用都成功返回.我认为这与Charles有关,它阻止我的应用程序与我的localhost服务器进行通信.
在Postman中,如果我尝试查询我的Android应用程序尝试查询的相同URL,它可以成功运行并且结果也成功记录在Charles中:
http://localhost:8443/ + my api endpoint **OR** http://localhost.charlesproxy.com:8443/ + my api endpoint
Run Code Online (Sandbox Code Playgroud)
在Postman中查询和在我的Android应用程序中查询之间的唯一区别是我的应用程序点击此URL 10.0.3.2而不是因为我正在使用模拟器: …
如果我查看stackoverflow应用程序的水平回收视图,我可以看到他们使用"渐弱边缘"技术,以便用户知道回收者视图的左侧和右侧有项目,他/她可以滚动.
在listview中,我认为通过调用Romain Guy(http://www.curious-creature.com/category/android/page/2/)所描述的下面的内容来启用此效果:
机器人:cacheColorHint = "#00000000"
在Recyclerview中不存在这样的选择.是否有内置方法允许这些淡化边缘用于recyclerview或者它只是必须是黑客?
我正在阅读GCM:https://developers.google.com/cloud-messaging/server
其中一个要求是服务器需要能够:
我使用Spring RestTemplate作为我的后端,它来自Spring Boot.似乎没有一种方法可用于在文档中设置我的重试策略:http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/ RestTemplate.html
另外,当我用Google搜索时,我找到了RetryTemplate,但它是Spring Batch的一部分,并没有扩展RestTemplate,这让我觉得它不应该用于Rest操作,而是Spring Batch操作,比如处理大量的事务:http://docs.spring.io/spring-batch/2.1.x/apidocs/org/springframework/batch/retry/support/RetryTemplate.html
有没有办法可以使用Spring RestTemplate进行指数退避?
我按照本教程实现了滚动时隐藏工具栏和FAB的行为:https://mzgreen.github.io/2015/06/23/How-to-hideshow-Toolbar-when-list-is-scrolling (第3部分)/
我已经粘贴了下面的行为示例.
现在,而不是仅包含textView的选项卡中的recyclerview中的那些单独项目,我已对其进行编码,以便它们保持图片(ImageView)并在其下方显示项目列表的回收者视图.
因此,有一个外部回收者视图,其中包含内部回收者视图列表.
内部的recyclerview不会滚动 - 我通过覆盖方法canScrollVertically()跟踪此线程中的答案来禁用它:禁用在子级Recyclerview android中的滚动.我也尝试启用滚动内部回收视图,但我遇到了同样的问题.
外部的recyclerview会滚动并具有显示/隐藏工具栏和FAB的行为.
当我通过按住图片(ImageView)滚动时,应用程序行为完全正常,显示并隐藏工具栏和FAB.但是,当我将手指放在内部回收站视图上进行滚动时,外部回收站视图会滚动并且列表会上下移动,但是显示/隐藏工具栏和FAB的行为永远不会被激活.
我有一种感觉,这是因为内部的recyclerview拦截了滚动而外部的recyclerview没有得到滚动事件来激活行为.
有谁知道如何确保外部的recyclerview也获得滚动事件,以便行为有效?
android floating-action-button android-toolbar android-recyclerview
我正在尝试获取已更新的对象的objectId - 这是我使用java驱动程序的java代码:
Query query = new Query();
query.addCriteria(Criteria.where("color").is("pink"));
Update update = new Update();
update.set("name", name);
WriteResult writeResult = mongoTemplate.updateFirst(query, update, Colors.class);
Log.e("object id", writeResult.getUpsertedId().toString());
Run Code Online (Sandbox Code Playgroud)
日志消息返回null.我在mongolab上使用mongo服务器3.0,因为我在免费套餐上,所以它不应该返回null.我的mongo shell也是:
MongoDB shell版本:3.0.7
有没有一种简单的方法可以返回我刚更新的文档的对象ID?如果我不能返回upsertedId,方法getUpsertedId()有什么意义?
为了做我想做的事,我目前必须发出两个非常麻烦的查询:
//1st query - updating the object first
Query query = new Query();
query.addCriteria(Criteria.where("color").is("pink"));
Update update = new Update();
update.set("name", name);
WriteResult writeResult = mongoTemplate.updateFirst(query, update, Colors.class);
//2nd query - find the object so that I can get its objectid
Query queryColor = new Query();
queryColor.addCriteria(Criteria.where("color").is("pink"));
queryColor.addCriteria(Criteria.where("name").is(name));
Color color = …Run Code Online (Sandbox Code Playgroud) android ×7
java ×3
resttemplate ×2
spring ×2
asynchronous ×1
genymotion ×1
listview ×1
localhost ×1
mongodb ×1
proxy ×1
snackbar ×1
spring-boot ×1