RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-208242

Turalllb's questions

Martin Hope
Turalllb
Asked: 2020-05-07 04:17:42 +0000 UTC

CoordinatorLayout ViewPager ,ViewPager里面的内容必须依赖外层的coordinator

  • 0

代码中排除的额外元素。

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_weight="1"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlwaysCollapsed|snap"
        app:popupTheme="@style/AppTheme.PopupOverlay">

    </android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>


<android.support.v4.view.ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

这是 ViewPager 中的片段,这是它们的标记

<android.support.v4.widget.NestedScrollView
    android:id="@+id/nested_scroll_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:fadeScrollbars="false"
    android:fillViewport="true"
    android:isScrollContainer="false"
    android:scrollbarAlwaysDrawHorizontalTrack="true"
    android:scrollbarAlwaysDrawVerticalTrack="true">


    <android.support.constraint.ConstraintLayout
        android:id="@+id/mainLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorQuestionBackground"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:orientation="vertical">

        <include
            android:id="@+id/question_tv"
            layout="@layout/question_tv"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="16dp"
            android:layout_marginRight="16dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/question_image" />

        <include
            android:id="@+id/question_image"
            layout="@layout/question_image"
            android:layout_width="match_parent"
            android:layout_height="145dp"
            android:layout_gravity="center_horizontal"
            android:visibility="gone"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <include
            android:id="@+id/radiogroup_answer"
            layout="@layout/radiogroup_answer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="16dp"
            android:layout_marginEnd="4dp"
            android:layout_marginRight="4dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/question_tv" />

        <include
            android:id="@+id/hint"
            layout="@layout/hint"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="4dp"
            android:layout_marginRight="4dp"
            android:layout_marginBottom="8dp"
            android:visibility="gone"
            app:layout_constraintBottom_toTopOf="@+id/next_question"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/radiogroup_answer"
            app:layout_constraintVertical_bias="0.050000012" />

        <include
            android:id="@+id/hint_button"
            layout="@layout/hint_button"
            android:layout_width="340dp"
            android:layout_height="40dp"
            android:layout_gravity="center_horizontal"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="16dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/radiogroup_answer"
            app:layout_constraintVertical_bias="1.0"
            app:layout_dodgeInsetEdges="top"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

        <include
            android:id="@+id/next_question"
            layout="@layout/next_question_button"
            android:layout_width="@dimen/next_question_width"
            android:layout_height="@dimen/next_question_height"
            android:layout_gravity="center_horizontal"
            android:layout_marginStart="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginBottom="16dp"
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

    </android.support.constraint.ConstraintLayout>


</android.support.v4.widget.NestedScrollView>


<ImageView
    android:id="@+id/expanded_image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000"
    android:clickable="true"
    android:focusable="true"
    android:scaleType="fitCenter"
    android:visibility="invisible"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    app:layout_dodgeInsetEdges="top" />

这里有两个问题: 1)在根FrameLayout中有一个ImageView,点击这个ImageView变得可见,缩放,但不在中间,它完全按照Toolbar高度值后退。2) ConstraintLayout 有@+id/hint_button 它应该放在屏幕的底部。可以看到 Toolbar 是否从屏幕上移除,如果它降低,它会离开屏幕。我想让他的行为让他留在屏幕上。但是我尝试使用 app:layout_dodgeInsetEdges="top" 没有成功,我根本看不到任何反应

android
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-01-23 16:42:28 +0000 UTC

在 backStack 中交换活动

  • 2

我在清单中和发送意图时阅读了有关标志的文章,但没有找到答案。告诉我,是否有可能实现这一点:第一个活动已移至第二个活动。我按下后退按钮,我拦截它,我希望当前活动进入堆栈,并调用下面的一个。我意识到使用标志可以调用第一个活动的新实例,但我只想将第一个活动移到上面。

android
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-01-12 05:57:10 +0000 UTC

处理 TagHandler 标签

  • 1

有一个 text: "Часть [part_1_11/]1.11[/part] содержит... "process and get text: "Часть 1.11 содержит...",其中 1.11 是通过添加part_1_11到 assets 中的 html 文件的路径获得的链接。
我深入研究了这个问题并意识到他们将其用于此问题Html.fromHtml(String sourse, int flags, ImageGetter imageGetter, TagHandler tagHandler),据我所知,第一个参数是我的文本,第二个参数对我来说不清楚,第三个不清楚,但是我知道您可以传递 null ,第四个是标签处理程序,据我了解,我必须实现。

public class MyTagHander implements Html.TagHandler{

    @Override
    public void handleTag(boolean b, String s, Editable editable, XMLReader xmlReader) {

    }
}

但我不知道如何处理文本。而且我不确定是否需要 TagHandler 来添加您自己的标签,而不是准备 html 以通过标准方式进行处理。基本上我很困惑

android
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-12-14 04:25:38 +0000 UTC

动态更改图像时使用哪种图像格式

  • 0

目的:考虑到图像是动态变化的,以矩形的形式在屏幕上方插入图像。对于问题,该程序创建了一个片段,其中根据问题替换图像。drawable放不进去,因为 有很多问题并写了一堆条件,以便为每个问题选择正确的资源而drawable不是选项。将所有内容放入assets并命名图像更容易,以便为图像创建正确的路径。我决定使用nine-patch,但jpg25 kb 中的图像开始重 180 kb。当然,你可以压缩到png-8,但这里也有一些陷阱,因为。我找到了 android studio 独立转换png-8为的信息png-24 当打包在 apk 中时。就是这样。你有什么建议?图像与 Spot 10 Difference 应用程序的要求不同。没有放大问题的图像。

android
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-12-12 00:13:29 +0000 UTC

如何将视图添加到位于滚动视图中的布局的底部

  • 1
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"> 

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/linearLayoutQuestion"
            android:layout_width="match_parent"
            android:layout_height="517dp"
            android:layout_above="@+id/button4"
            android:layout_alignParentTop="true"
            android:orientation="vertical">
            ЗДЕСЬ ВЬЮХи которые добавляются динамически, во время исполнения кода

            </LinearLayout>

        <Button
            android:id="@+id/button4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:text="Button" />


    </RelativeLayout>
</ScrollView>

在此处输入图像描述

在 LinearLayout 中添加视图时,按钮应该留在底部,如果视图很多,那么界面应该滚动,但按钮仍然在底部。如何做到这一点?如果您删除 fillViewport ,则仅保留按钮,该按钮将位于屏幕顶部。

这个 xml 在这里作为标记TabItem

<?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:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ui.LearnTickets.LearnTickets">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_weight="1"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay"
            app:title="@string/app_name">

        </android.support.v7.widget.Toolbar>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.design.widget.TabItem
                android:id="@+id/ticket_tabs"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1" />

            <android.support.design.widget.TabItem
                android:id="@+id/ticket_tabs1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="2" />


        </android.support.design.widget.TabLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>
android
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-12-06 07:33:52 +0000 UTC

ScrollView 没有完全滚动 TableLayout

  • 0

我有 40 个按钮,每个按钮都应该创建自己的片段。滚动有效,但并非一切都适合。

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:scrollbars="vertical">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TableLayout
            android:id="@+id/TableLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button
                    android:id="@+id/button41"
                    android:layout_width="wrap_content"
                    android:layout_height="500dp"
                    android:layout_weight="1"
                    android:text="1" />

                <Button
                    android:id="@+id/button42"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="2" />

                <Button
                    android:id="@+id/button43"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="3" />

                <Button
                    android:id="@+id/button44"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="4" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button
                    android:id="@+id/button37"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="5" />

                <Button
                    android:id="@+id/button38"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="6" />

                <Button
                    android:id="@+id/button39"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="7" />

                <Button
                    android:id="@+id/button40"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="8" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button
                    android:id="@+id/button33"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="9" />

                <Button
                    android:id="@+id/button34"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="10" />

                <Button
                    android:id="@+id/button35"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="11" />

                <Button
                    android:id="@+id/button36"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="12" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button
                    android:id="@+id/button29"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="13" />

                <Button
                    android:id="@+id/button30"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="14" />

                <Button
                    android:id="@+id/button31"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="15" />

                <Button
                    android:id="@+id/button32"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="16" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button
                    android:id="@+id/button25"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="17" />

                <Button
                    android:id="@+id/button26"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="18" />

                <Button
                    android:id="@+id/button27"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="19" />

                <Button
                    android:id="@+id/button28"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="20" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button
                    android:id="@+id/button21"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="21" />

                <Button
                    android:id="@+id/button22"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="22" />

                <Button
                    android:id="@+id/button23"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="23" />

                <Button
                    android:id="@+id/button24"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="24" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button
                    android:id="@+id/button7"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="25" />

                <Button
                    android:id="@+id/button3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="26" />

                <Button
                    android:id="@+id/button2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="27" />

                <Button
                    android:id="@+id/button"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="28" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button
                    android:id="@+id/button9"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="29" />

                <Button
                    android:id="@+id/button10"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="30" />

                <Button
                    android:id="@+id/button11"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="31" />

                <Button
                    android:id="@+id/button12"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="32" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button
                    android:id="@+id/button13"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="33" />

                <Button
                    android:id="@+id/button14"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="34" />

                <Button
                    android:id="@+id/button15"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="35" />

                <Button
                    android:id="@+id/button16"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="36" />
            </TableRow>

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <Button
                    android:id="@+id/button17"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="37" />

                <Button
                    android:id="@+id/button18"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="38" />

                <Button
                    android:id="@+id/button19"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="39" />

                <Button
                    android:id="@+id/button20"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="40" />
            </TableRow>
        </TableLayout>
    </RelativeLayout>


</ScrollView>

在此处输入图像描述

添加了寻求解决问题的建议,但没有结果。

android
  • 2 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-11-29 00:57:58 +0000 UTC

哪个线程将数据传递给视图

  • 0

比方说MVP。演示者为回调定义了一个接口

dataManager.downloadDataFromNetwork(currentDate, ACCESS_KEY, currentCurrency, new Callback<PostModel>() {
                @Override
                public void onResponse(Call<PostModel> call, Response<PostModel> response) {
                    PostModel postModel = response.body();
                    validationOfData(postModel);
                }

                @Override
                public void onFailure(Call<PostModel> call, Throwable t) {
                    getView().showToast("Сетевая ошибка");
                }
            });

View 将数据传递给 Presenter,在 Presenter 中实现接口,然后框架retrofit 2调用网络。至此,一切都由应用程序的主线程完成。这里主线程被“释放”并继续监听用户的动作。
接下来,在 add 中向网络发出请求。溪流。结果被传递给回调接口的实现,它位于presenter中。据我了解,这一切都是如此。流动。而且他还调用了视图的接口方法并更新了视图..我理解一切正确吗?

java
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-11-27 04:59:45 +0000 UTC

在这种情况下如何正确处理 NPE

  • 0

有一个演示者,在它的各种方法中都有对方法的调用,该方法getView()位于基本演示者中。

protected V getView() {
        return view;
    }

如果view == null方便我不执行该方法并且什么都不做。在我的单屏应用的情况下,这是理想的。try/if 但我不想写一堆 blocks 。我想在尝试使用view一次之前检查并停止进一步的代码执行。

如果我在方法中以某种方式处理这种情况,getView()我仍然必须执行return view;

UPD,我看到我的问题并不清楚。这是详细信息。

public class BasePresenter<V extends BaseView> implements MvpPresenter<V> {
    private V view;

    @Override
    public void attachView(V view) {
        this.view = view;
    }

    @Override
    public void detachView() {
        view = null;
    }

    protected V getView() {
        return view;
    }  
}

好吧,主持人本人:

public class MainMenuPresenter<V extends MainView> extends BasePresenter<V>
        implements MainPresenter<V> {

    public void setData(PostModel postModel) {
            ....
            getView().refreshSpinner();
            ....
            getView().refreshAdapterModelDate();
        }


     private void validationOfData(PostModel postModel) {
            if (postModel.getDate() == null) {
                getView().refreshAdapterModelDate();
                getView().showToast("В");
            } else if (!postModel.getDate().equals(currentDate)) {
                getView().refreshAdapterModelDate(); 
                getView().showToast("");
            } else {
                //Если всё в порядке
                setData(postModel);
                dataManager.setDataBase(postModel);
            }
        }

    }
java
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-11-08 07:38:34 +0000 UTC

为什么Activity模块里有Presenter Provider

  • 0

我在 github 上 找到了一个项目,它作为 Dagger 2 的 MVP 的参考实现。所以,令我惊讶的是,Activity它在模块中有类似的方法:

    @Provides
    @PerActivity
    MainMvpPresenter<MainMvpView> provideMainPresenter(
            MainPresenter<MainMvpView> presenter) {
        return presenter;
    }

由于我们在以下情况下创建了活动组件OnCreate():

 mActivityComponent = DaggerActivityComponent.builder()
            .activityModule(new ActivityModule(this))
            .applicationComponent(((MvpApp) getApplication()).getComponent())
            .build();

原来,当屏幕翻转时,演示者也会死亡。毕竟,将主要活动的演示者的实例与生活联系起来更合理application吗?那么为什么presenter提供者在activity模块中呢?

android
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-10-17 04:26:12 +0000 UTC

为什么Application继承者中的方法要带Context

  • 0

从github得到这段代码

    public class GithubClientApplication extends Application {
    
    
    
    public static GithubClientApplication get(Context context) {
        return (GithubClientApplication) context.getApplicationContext();
    }
    
    @Override
    public void onCreate() {
        super.onCreate();
    }
   }

不止一次,类似的代码已经遇到过,在 heirApplication中,该方法将上下文作为输入,并以这种方式将此上下文转换为类类型。

为什么这个类需要上下文?他有他自己的,还是这些背景有什么不同?通常这样的时刻是从继承人的阶级中召唤出来的Activity。我假设需要上下文参数,以便只有有权访问上下文的类才能获得继承类的实例Application。

我还看到了在方法中上下文从一个扩展类传递Activity 到另一个扩展类的代码Activity

java
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-07-26 17:34:54 +0000 UTC

如何在不同线程中计算物理和渲染图形?

  • 5

我决定添加一个玩具:屏幕上有 4 个人物在移动。例如,该方法figure.update()重新计算图形的坐标。还有第五个数字,我通过触摸传感器来控制它。被覆盖的方法onTouchEvent(MotionEvent event)从传感器读取数据并更新我的受控图形的坐标。现在渲染进展如何:完成figure.update()对于所有人物,画。但我控制的图形也是在第二步绘制的,只是它的坐标会随着传感器的触摸而变化。那些。可能会出现一种情况,在我绘制的那一刻,图形的坐标已经更新,X已经更新,Y变量还没有更新。结果,将绘制出不完全正确的图形位置。也许在 60 fps 时这些侧柱并不明显.. 我个人在开始游戏时没有看到任何此类错误,好像一切都经过准确计算。但毕竟按照逻辑,应该有错误..不应该有这样的错误:那个渲染正在进行中,这个图的坐标是由传感器更新的,因为传感器的工作去在 UI 线程中,其余的物理和渲染计算在附加中。溪流。事实证明我必须将这些变量标记为同步,

我会给出代码,但我认为这里是多余的,我再重复一遍:在 UI 线程中,图形的值根据传感器的结果而变化,并且在附加值中。线程正在绘制这个数字。为什么没有因绘图需要UI线程中当前正在更改的坐标这一事实而导致异常。或者为什么在沿着传感器的急剧移动过程中 X 坐标发生变化,而 Y 仍然具有旧值的这种时刻对眼睛来说并不明显。
我想到了以下答案:UI 线程只需要更新从传感器接收到的两个变量,它很快就能解决这个问题。添加。流始终具有从相同传感器读数读取的两个坐标。但问题仍然存在:如果 UI 经常更新坐标(我在屏幕上快速移动手指),那么为什么会额外更新。当坐标正忙于从 UI 线程写入时,线程不会遇到这种情况。

java
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-06-27 23:14:41 +0000 UTC

类加载,初始化顺序

  • -2
public class A{

    static int a = 1111;
    static
    {
            a = a-- - --a;
    }

    {
            a = a++ + ++a;
    }

     public static void main(String[] args)  {
           System.out.println(a);
        }
    }

他们询问程序将输出什么。我很清楚,如果我们还没有创建类的实例,那么类级(静态)变量将被初始化,并且静态块也将被执行,即使没有创建类实例。而这里的答案是2。因为在调用的时候,只执行了静态初始化块。但我有一个不同的问题。我认为会有一个 NPE 异常,因为该变量а还不存在。我想,我这样做是因为我相信public static void main(String[] args)首先执行入口点,然后按顺序进行初始化。

所以在什么时候静态字段和统计数据被初始化了。类块А?

java
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-06-26 17:05:30 +0000 UTC

开关:在中断前使用花括号

  • 5
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.start:
            {
                Intent intent = new Intent();
                intent.setClass(this, Menu.class);
                startActivity(intent);
            }
            break;  
        case R.id.records: 
            Intent intent = new Intent();
            intent.setClass(this, RecordList.class);
            startActivity(intent);
            break;   
    }
}

在第一个按钮的处理中有花括号,我想了解它们在这种情况下是如何工作的。intent如果将它们删除,那么即使有操作员,也会抱怨两个相同的名称break。如果我突然编写这样的代码,第一个按钮将不遵循创建的意图,而我将能够单击第二个按钮,那么就会发生一些不好的事情。

java
  • 2 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-06-26 05:16:06 +0000 UTC

自定义按钮。单击另一个按钮时的动画

  • 3

在游戏菜单中,您需要一个按钮来选择游戏模式。常规下拉微调器不起作用。我想要这样的东西:

                 Начать игру 
                 < Режим 1 > 
                  Рекорды
                 Настройки
                   Выход  

或者箭头会导致按钮移动的动画,而不是模式 1,会出现模式 2 按钮。重要的是要有流畅的动画。
以下是如何实现它。那么第一个箭头是 ImageView 中间的按钮吗?或在 xml 中描述为动画的不可点击按钮。当你点击箭头时,你需要调用离开ImageView到屏幕右侧和到达屏幕左侧的不同文本的动画。(甚至更好地与 一起使用TextView)backgroud嗯,总的来说,我认为理解我想要的并不难。我想了解如何正确实施它,以免从我的错误中吸取教训,遗憾的是没有时间这样做。

我试过Animation类,它有4种动画,这里是文章开头的gif 。有一个按钮离开右侧并返回右侧的选项,我不知道是否可以对其进行调整,以便返回位于屏幕左侧,是否可以更改按钮文本动画过程中的正确时间?

java
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-06-25 18:33:20 +0000 UTC

挂在单例上的监听器不起作用

  • 0

目标是MediaPlayer从任何班级访问以随时暂停或开始播放另一首旋律。可以在子类中创建Application静态实例MediaPlayer,但我们仍然需要处理现在将播放的旋律的方法、释放资源的方法等等。我不想将所有这些都堆积在子类中Application,特别是因为它已经有一个方法可以将其上下文返回给我,以便我可以在单例中进行初始化MediaPlayer。我最终创建了一个单独的单例类。

public class MediaPlayerSingleton implements MediaPlayer.OnCompletionListener {

    private static MediaPlayerSingleton mpSingleton;
    private MediaPlayer mediaPlayer;

    private MediaPlayerSingleton() {
    }

    static MediaPlayerSingleton getInstance() {
        if (mpSingleton == null) mpSingleton = new MediaPlayerSingleton();
        return mpSingleton;
    }


    void play() {
        mediaPlayer = MediaPlayer.create(MyApplication.getAppContext(), R.raw.melodiya);
        mediaPlayer.start();
        mediaPlayer.setOnCompletionListener(this);
    }

    @Override
    public void onCompletion(MediaPlayer mp) {
      releaseMP();
      mediaPlayer = MediaPlayer.create(MyApplication.getAppContext(), R.raw.acdc);
    }

    private void releaseMP(){
        if(mediaPlayer != null){
            mediaPlayer.release();
            mediaPlayer = null;
        }
    }

现在我在一些活动上调用该方法getInstance.play();。但是在播放结束时,监听器不起作用。我认为我认为它会起作用是错误的,因为该班级不是Activity重点关注的 . 没有它你看不到这里Service吗?或者还有什么方法可以在没有服务的情况下实现监听器?可能,如果您将侦听器放在所有活动上,那么这会起作用,但看起来不太好。

java
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-06-25 17:08:39 +0000 UTC

单身人士。Application 类的子级中的私有变量

  • 2

论坛上的一个答案说:

如果可能,最好在具有实例引用的 Application 类的子类中创建私有变量,而不是在单例类本身中创建私有静态变量。

我很困惑,我无法理解其中的区别,请显示根据此建议完成所有操作的代码以及变量在类本身中的代码。

好吧,类本身的变量如下所示:

public class Singleton { 
 private static Singleton instance; 

 private Singleton (){} 

 public static Singleton getInstance(){ 
  if (null == instance){ 
   instance = new Singleton(); 
  } 
  return instance; 
 } 
}

我不明白子类中的变量是什么Application样的......相反,因为我不明白如果遵循这个建议会有什么好处。

这个问题的公认答案是我的问题 Singleton in Android - evil?

java
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-06-13 05:33:05 +0000 UTC

在 Sqlite 中存储从 json 获得的对象数组

  • 1

json类型 "rates":{"AAA":5.023852,"BBB":77.682521}

一开始我都是手动做的,然后我AsyncTask得到json了,把它解析到我的课堂上

class ModelData {

    private String name;
    private Double value;

    ModelData(String name, Double value) {
        this.name = name;
        this.value = value;
    }
}

sqLite并将响应本身缓存在数据库中json。毕竟List<ModelDate>,我不能用 sqLite 写。这是另一个子问题:我是否理解正确,为了在 sqLite 中保存对象,我们创建一个重复该对象的 json,并将其作为字符串悄悄地保存在数据库中。并且ORMLite经常听到,但现在我认为需要将对象存储在数据库中。不知道她是怎么做到的,也许她也自动创建json并存储)

然后我决定实现retrofit 2(它必须最终实现),这自然是失去了一些灵活性,这就是问题所在:我的答案被解析了

@SerializedName("rates")
@Expose
private List<ModelData> ratesList;

但是我怎样才能ratesList将它保存在sqLite. 我知道我可以以某种方式将此工作表转换并保存回 Json,但是从数据库中读取时,我将不得不再次解析,而这仍然是一个解析器代码,尽管已经存在一个。

这就是我想要的:在 POJO 模型中,分别解析字段和原始 json 本身(需要什么注释来获取整个 json?或者需要什么)并且还能够解析从数据库接收到的 json 相同POJO 模型类。

我认为这不是一个糟糕的例子,说明 retrofit 2两者都sqLite被剥夺了灵活性,结果证明对于一个小项目来说是多余的,只有当项目增长时,我才会从它们中受益。

UPD1我意识到 您可以将其余 api 的接口配置为接受原始 json,例如:

@GET("{date}")
Call<JsonObject> getData(@Path("date") String date, @Query("access_key") String accessKey, @Query("base") String  base);

但是我以后如何使用这个 JsonObject 的 POJO 模型来解析它,并将 Gson 转换器添加到改造中。这正是我在这个库中不明白的地方,解析中一般涉及到什么地方和什么方法。在什么时候连接转换器,可能已经在 okhttp3 级别的某个地方......总的来说,我厌倦了挖掘这个库

android
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-06-12 02:04:42 +0000 UTC

改造2,解析响应

  • 0

假设一个元素数组以 json 形式到达,每个元素都有一个名称和一个值。{"AAA":4.523703,"BBB":85.195162}. 让我们建立一个 POJO 模型

        @SerializedName("AAA")
        @Expose
        private Double AAA;
        @SerializedName("BBB")
        @Expose
        private Double BBB;

但最后我需要listView在一行中显示名称和值,所以我需要Map. 是否可以retrofit 2使用注释来实现这一点?为了在Map<String, Double> AAA = new HashMap<>() Maybe retrofit 2中得到准确的处理,或者你必须手动解析它。我知道如何手动完成。

问题更新
我正在提出请求

@GET("{date}")
Call<String> getData(@Path("date") String date, @Query("access_key") String accessKey); 

如您所见,我正在尝试获取一个字符串,我希望原始 json 来解析自己。我没能做到这一点。理论上,我根本不应该使用任何转换器,但如果我关闭转换器,我会遇到异常。这是第一个问题。第二个问题是如何不自己解析,而是使用POJO模型。最终,您需要一个 HashMap,其中

AAA = 4.523703
BBB = 85.195162

什么对象应该在Call<>

android
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-06-01 03:41:01 +0000 UTC

二分查找,数组要求

  • 1

我一直以为这是某种复杂的算法,但看了之后才发现是垃圾。但是他们说我做不到。我决定尝试几个晚上,我得到了一个成功的算法。

我还不需要提示,只有一个问题,我无法以明确的形式找到答案(同样,我不想意外阅读提示)。

告诉数组有什么条件可以进行二分查找。这次有条不紊。我们应该知道它是增加还是减少?

我知道您可以检查它是什么,并根据此选择一种或另一种算法。但是,如果事实证明该算法必须对减少和增加都是通用的,那么我的实现似乎失败了。
剩下的只是添加一个条件,如果数组正在减少,请使用反向算法。

 Integer binarySearch(int value) { 
        middle = array.length / 2;
        lastElement = array.length;
        firstElement = 0;

        while (array[middle] != value) {
            if (array[middle] < value) {
                firstElement = middle;
                middle = (middle + lastElement) / 2;
                if (middle == firstElement) return null;
            } else {
                lastElement = middle;
                middle = (firstElement + lastElement) / 2;
                if (middle == lastElement) return null;
            }
        }
        return middle;
    }

UPD 在我的二进制搜索实现中发现了两个错误。我一直在寻找 JDK 中存在 20 年的错误,但首先我发现没有元素的数组会使我的代码崩溃。所以有必要补充一下,这里检查一下: if(array.length == 0) return null;
过了一会儿,我发现第二个错误是在JDK中,我没有找到,因为我没有考虑到非int范围数可以的情况来。是的,一个非int范围不会来,但它可能会出现在更远的行中 middle = (firstElement + lastElement) / 2; 因此,我这样重写它middle = firstElement/2 + lastElement/2但是后来我决定除法运算比减法或加法更昂贵,并这样写

middle = (lastElement - firstElement)/2 + firstElement;
алгоритм
  • 1 个回答
  • 10 Views
Martin Hope
Turalllb
Asked: 2020-05-20 06:42:05 +0000 UTC

哪个周期会更快

  • 1
ArrayList arrayList = new ArrayList();
        arrayList.add(1);
        arrayList.add("два");

        //Этот?
        for(int i = 0; arrayList.size() > i; i++){
            System.out.println(arrayList.get(i));
        }

        //или этот в котором как я понимаю будет приведение типов?
        for (Object temp: arrayList){
           System.out.println(temp);
        }

我们知道在处理集合时 forEach 比 for 慢(尽管现在可能已经在优化)但是类型转换是否会产生额外的成本,或者编译器会看到我只是打印元素,并且无论如何它们都会被转换为 String并优化这是?

UPD:
在这种情况下,我们在工作表中有 Integer。在 ForEach 中,一切也是整数。在 forEach 的第一个变体中,有一个对象。

ArrayList<Integer> arr = new ArrayList<>();
        arr.add(1);
        arr.add(2);
        arr.add(5);

 for (Integer temp : arr ) {
      System.out.println(temp);
 }

问题是对于 forEach 中的对象是否会有不必要的类型转换,但在 for 我们不会转换为 Object。在这一点上我很困惑

java
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5