小编May*_*ies的帖子

RxJava组合请求序列

问题

我有两个Apis.Api 1给了我一个项目列表,Api 2给了我更多关于我从Api获得的每个项目的详细信息.到目前为止,我解决它的方式导致性能不佳.

问题

在Retrofit和RxJava的帮助下,快速,快速地解决了这个问题.

我的方法

在片刻我的解决方案看起来像这样:

第1步:Single<ArrayList<Information>>从Api 1 执行Retrofit .

第2步:我遍历这些项目并向Api 2发出请求.

第3步:改造退货按顺序执行Single<ExtendedInformation>每个项目

步骤4:在完成Api 2的所有调用完成后,我为组合信息和扩展信息的所有项创建一个新对象.

我的守则

 public void addExtendedInformations(final Information[] informations) {
        final ArrayList<InformationDetail> informationDetailArrayList = new ArrayList<>();
        final JSONRequestRatingHelper.RatingRequestListener ratingRequestListener = new JSONRequestRatingHelper.RatingRequestListener() {
            @Override
            public void onDownloadFinished(Information baseInformation, ExtendedInformation extendedInformation) {
                informationDetailArrayList.add(new InformationDetail(baseInformation, extendedInformation));
                if (informationDetailArrayList.size() >= informations.length){
                    listener.onAllExtendedInformationLoadedAndCombined(informationDetailArrayList);
                }
            }
        };

        for (Information information : informations) {
            getExtendedInformation(ratingRequestListener, information);
        }
    }

    public void getRatingsByTitle(final JSONRequestRatingHelper.RatingRequestListener ratingRequestListener, final Information information) {
        Single<ExtendedInformation> …
Run Code Online (Sandbox Code Playgroud)

java android reactive-programming rx-java rx-android

21
推荐指数
2
解决办法
1万
查看次数

折叠工具栏仅适用于导航视图中的一个片段

问题

我有一个带有不同碎片的导航抽屉.每个Fragment应该使用的默认工具栏,除了Fragment需要折叠的工具栏Toolbar.

我的问题

如何在片段的工具栏之间切换?

java xml android android-layout android-fragments

9
推荐指数
3
解决办法
3138
查看次数

Android屏幕闪烁显示/隐藏系统栏

问题

当用户向上滚动RecyclerView并在用户向下滚动时隐藏系统栏时,我想显示系统栏.然而,使用我的方法它可以工作,但内容在显示/隐藏过程中扼杀地移动和闪烁.U为此行为上传了视频:https://drive.google.com/open?id = 0B_b9EpRt -zyHVW54dkQzcXdUTXM

我的方法

基本上我有这两种方法:

   private void hideSystemUI() {
        getActivity().getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
                        View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                        | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                        | View.SYSTEM_UI_FLAG_IMMERSIVE);

    }


    private void showSystemUI() {
        getActivity().getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }
Run Code Online (Sandbox Code Playgroud)

我将此onScrollListener设置为RecyclerView以隐藏和显示状态栏,具体取决于滚动:

   mFragmentListBinding.fragListRvMovies.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);

                    if (dy > 5) {
                        //   hideSystemUI();
                        //     SystemUIHelper.hide(getActivity());
                        hideSystemUI();

                    } else if (dy < -5) { …
Run Code Online (Sandbox Code Playgroud)

java xml android android-layout android-recyclerview

8
推荐指数
1
解决办法
880
查看次数

选项卡布局内的水平回收器视图

问题

我有一个选项卡布局,在选项卡布局内有一个水平回收器视图。有时,当我尝试滑动回收器视图时,它只是更改选项卡位置。

问题

是否有可能回收器视图区域中的所有触摸事件都不会报告到选项卡布局,以便回收器视图区域中的所有触摸事件只能更改回收器视图位置而不能更改选项卡位置?

java xml layout android android-recyclerview

5
推荐指数
1
解决办法
881
查看次数

ViewPager内部的水平Recycler视图不滚动

问题

我在ViewPager中的NestedScrollView中有一个水平的RecyclerView.现在,当我尝试滚动RecyclerView时,有时它会滚动,但有时只有ViewPager滚动.

代码

这就是我的RecyclerView XML的样子:

<android.support.v7.widget.RecyclerView
            android:id="@+id/sidescroll"
            android:layout_below="@+id/movie_more_movies2"
            android:layout_marginTop="@dimen/material_layout_keylines_horizontal_margin"
            android:layout_marginBottom="@dimen/material_layout_keylines_horizontal_margin"
            android:layout_width="match_parent"
            android:orientation="horizontal"
            app:layoutManager="android.support.v7.widget.LinearLayoutManager"
            android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)

这就是RecyclerView所在的嵌套滚动的样子:

<android.support.v4.widget.NestedScrollView
    android:id="@+id/detail_holder"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:descendantFocusability="blocksDescendants"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    >
Run Code Online (Sandbox Code Playgroud)

这是viewpager xml:

<com.mt.moviesiwanttowatch.ui.ViewPagerWithHorizontalRecyclerView
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipChildren="false"
            android:clipToPadding="false"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
Run Code Online (Sandbox Code Playgroud)

我正在使用此自定义ViewPager:

public class ViewPagerWithHorizontalRecyclerView extends ViewPager {

    public ViewPagerWithHorizontalRecyclerView(Context context) {
        super(context);
    }

    public ViewPagerWithHorizontalRecyclerView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
        if(v instanceof …
Run Code Online (Sandbox Code Playgroud)

java xml android android-layout android-recyclerview

5
推荐指数
1
解决办法
2787
查看次数

Java Regex 提取两个字符串之间的字符串

问题

我有一个这样的模式“提名?奥斯卡”或“提名 2 座金球奖。提名?奥斯卡。30 次赢得 18 项提名” 我想确定 ? 用正则表达式,所以奥斯卡的数量。

我试过的

好像有

对应这个问题:在java中提取两个字符串之间的字符串

如何在两个字符串之间找到一个值?我试过这种模式:

final Pattern pattern = Pattern.compile("for(.*?)Oscar");
Run Code Online (Sandbox Code Playgroud)

接下来我尝试了这个问题:Java - 在两个字符串之间获取所有字符串的最佳方法?(正则表达式?)

  final Pattern pattern = Pattern.compile(Pattern.quote("Nom") +"(.*?)"+ Pattern.quote("Oscar"));
Run Code Online (Sandbox Code Playgroud)

我的其余代码:

final Matcher matcher = pattern.matcher("Nom for 3 Oscar");
    while(matcher.find()){

    }
Log.d("Test", matcher.group(1));
Run Code Online (Sandbox Code Playgroud)

所有这些模式都会导致此异常:

java.lang.IllegalStateException:到目前为止没有成功的匹配

我想我只是监督一些非常简单的事情。

你们能帮帮我吗?

编辑


所以问题是我在循环后调用 matcher.group(1) 。我误解了 find 方法的工作原理。然而,当我在循环内调用 matcher.group(1) 时,这段代码确实有效。

   final Pattern pattern = Pattern.compile("for(.*?)Oscar");
    final Matcher matcher = pattern.matcher("Nom for 3 Oscar");
        while(matcher.find()){
         Log.d("Test", matcher.group(1));
        }
Run Code Online (Sandbox Code Playgroud)

java regex string android illegalstateexception

4
推荐指数
1
解决办法
6835
查看次数

ConstraintLayout 垂直链权重

问题


我有简单的计算器布局来测试约束布局。我已经实现了创建这个布局:BasicLayout但是这个布局的问题是,按钮上有空白空间。所以我想创建一个带有权重的垂直链来填充整个屏幕。

我试过的


所以我想出了这个布局:(见编辑)

然而结果不是我想要的,而是产生了这个布局:我的尝试

所以不知何故它忽略了垂直权重。任何人都知道如何解决它?

编辑


一段时间后,我实现了这个Closer,它更近了,但重量仍然没有改变:新代码:

<android.support.constraint.ConstraintLayout 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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <View
        android:id="@+id/test"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="?attr/colorPrimary"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_weight="5"
        app:layout_constraintBottom_toTopOf="@+id/btn_space"
         />





    <com.envidual.gradecalculator.TextViewRoboto
        android:id="@+id/btn_space"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:gravity="center"
        android:text=""
        android:textSize="30dp"
        app:layout_constraintHorizontal_weight="3"
        app:layout_constraintVertical_weight="1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/button155"
        app:layout_constraintTop_toBottomOf="@+id/test"
        app:layout_constraintBottom_toTopOf="@+id/btn_13"
     />


    <com.envidual.gradecalculator.TextViewRoboto
        android:id="@+id/button155"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:gravity="center"
        android:text="AC"
        android:textSize="20dp"
        app:layout_constraintBaseline_toBaselineOf="@+id/btn_space"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintLeft_toRightOf="@+id/btn_space"
        app:layout_constraintRight_toLeftOf="@+id/btn_clr" />

    <com.envidual.gradecalculator.TextViewRoboto
        android:id="@+id/btn_clr"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:gravity="center"
        android:text="CLR"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="@+id/button155"
        app:layout_constraintHorizontal_weight="1"
        app:layout_constraintLeft_toRightOf="@+id/button155"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/button155" />


    <com.envidual.gradecalculator.TextViewRoboto
        android:id="@+id/btn_13"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="?attr/selectableItemBackgroundBorderless"
        android:gravity="center"
        android:text="13" …
Run Code Online (Sandbox Code Playgroud)

java xml layout android android-constraintlayout

3
推荐指数
1
解决办法
9747
查看次数