小编OLe*_*ert的帖子

Android AppBarLayout重叠listview

我正在编写一个与ContentProvider一起使用的简单应用程序,我有一个db,一个ContentProvider,一个主要活动,一个使用ContentResolver将命令转发到ContentProvider的类.在gui上我只想显示存储在db中的所有项目.我从头开始创建这个项目,在创建Activity时,主要布局有一个CoordinatorLayout,带有AppBarLayout,没关系,我创建了一个ListView,除了appBarLayout重叠ListView,在listview的第一项下面,一切正常被AppBarLayout隐藏. 在此输入图像描述

我尝试使用android:layout_below我的ListView,但它不起作用,如果我使用android:layout_marginTop然后我的ListView是在AppBarLayout下,但我没有找到这个解决方案很好.

在AppBarLayout下有没有干净简单的方法来获取ListView?

在我的activity_main布局下面:

<?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:background="@color/holo_light_background"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/bar"
        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:background="?attr/colorPrimary"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>


    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/bar"/>


    <android.support.design.widget.FloatingActionButton ...>

    <android.support.design.widget.FloatingActionButton ...>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android listview android-appbarlayout

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

尝试访问其他文件时切换到 Kotlin DSL 未解析的参考

我在尝试对我的 gradle 文件使用 Kotlin DSL 时遇到错误。

build.gradle(app)我有一个函数来检索存储在文件中的 api 密钥中keys.properties,Groovy 中的函数如下:

// Retrieve key api
def getApiKey() {
    def keysFile = file("keys.properties")
    def keysProperties = new Properties()
    keysProperties.load(new FileInputStream(keysFile))
    def apiKey = keysProperties['API_KEY']
    return apiKey
}
Run Code Online (Sandbox Code Playgroud)

当切换到 Kotlin DSL 时,我天真地将函数更改如下:

// Retrieve key for TMDB api
fun getApiKey() {
    val keysFile = file("keys.properties")
    val keysProperties = Properties()
    keysProperties.load(FileInputStream(keysFile))
    val apiKey = keysProperties["API_KEY"]
    return apiKey
}
Run Code Online (Sandbox Code Playgroud)

然后构建返回以下错误:

.../app/build.gradle.kts:13:26: Unresolved reference: Properties
Run Code Online (Sandbox Code Playgroud)

有谁知道如何解决这个问题?

编辑

按照 #bam bam 的建议,添加导入import …

android kotlin gradle-kotlin-dsl

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

在MVP上下文中使用Service作为Presenter是一个好主意

简短说明我的问题是:在MVP架构中,使用服务作为演示者来控制实现为服务的模型是个好主意吗?

替代问题:使用服务来控制另一个服务是一个好主意吗?

上下文:

我正在编写一个与蓝牙传感器通信的应用程序.该应用程序具有服务 (aka BluetoothService),用于建立连接并管理与传感器的通信.该应用程序有几个片段,但只有少数与蓝牙传感器的操作有关.用户应该能够开始操作,导航到不同的片段,然后观察传感器完成的操作的结果.

我的目的:

我想写一个组件(aka BluetoothController),它在传感器(在我的app中表示BluetoothService)和应用程序的其余部分之间建立链接.该BluetoothController包含描述必须由传感器(只需一个人操作,串口操作,操作的类型,...)进行什么样的操作对象,因此,BluetoothController公司的宗旨是让操作是独立的蓝牙传感器,然后能够使用模拟蓝牙类测试应用程序.我认为BluetoothService作为模特和 BluetoothController主持人,我错了吗?

为何选择服务:

  • 因为如果用户在片段之间导航,它不会死亡
  • 因为它可以通过整个应用程序访问 bindService
  • 因为bindService是唯一的入口点,我想我可以控制一次只完成一个操作
  • 因为我将Service视为一个活动组件,所以它可以继续接收数据,即使它没有任何约束

这项服务既可以启动也可以绑定(如音乐播放器):

  • 即使没有绑定任何组件也能继续运行,
  • 轻松沟通

所有服务都将在应用程序进程中,以便在没有绑定程序的情况下完成通信,而不是方法调用

任何建议都会非常感谢,提前感谢

为什么不是别的东西:

  • RetainedFragment(对我来说)只是容器
  • pojo presenter只是视图和模型之间的网关,如果它们没有附加到视图,它们应该会死掉.

结论

我错了吗?你觉得这个架构有困难吗?还有其他适合我目的的Android组件吗?

任何建议都将受到高度赞赏,谢谢你的进步

mvp android bluetooth android-service

6
推荐指数
0
解决办法
728
查看次数

Java 策略模式 - 我可以在 Context 类中委托策略实例化吗?

我目前正在自学设计模式。当我研究策略模式时,我发现一些对我来说看起来很奇怪的东西。我查找了有关此模式的讨论,但没有人回答我的问题...这就是我如何实现策略模式以使其干净、保持封装并使添加新策略变得容易。这里解释我的问题是“规范”策略模式:

public interface Strategy {
    public void run();
}

public class stratConcrt1 implements Strategy {/*run() implementation*/}
public class stratConcrt2 implements Strategy {/*run() implementation*/}

public class Context {
    private Strategy strategy;

    public Context(Strategy strat) {
        this.strategy = strat;
    }

    public void runStrategy() {
        this.strategy.run()
    }
}


public class Client {
    public void main(Strings[] args) {
        Context cx;

        cx = new Context(new stratConcrt1())
        cx.runStrategy();

        cx = new Context(new stratConcrt2())
        cx.runStrategy();
    }
}
Run Code Online (Sandbox Code Playgroud)

我明白发生了什么,但让客户了解可以应用的不同策略,我感觉很奇怪。对我来说,让 Context 实例化不同的策略而不是 Client 会更干净,因为 Context 处理策略,它应该(至少在我看来)是唯一能够实例化策略的策略。

我使用 JavaFx 实现了一个小示例,与上面的代码有一些差异: …

java design-patterns strategy-pattern

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

c#从System.Reflection.FieldInfo转换为用户定义的类型

我有以下类Point和Class2.我的目的是在Class2中检索所有Points实例以将它们存储在List中.

public class Point
    {
        int x;
        int y;
        string col;

        public Point(int abs, int ord, string clr)
        {
            this.x = abs;
            this.y = ord;
            this.col = clr;
        }

        public string toColor()
        {
            return this.col;
        }

        public int Addition()
        {
            return (this.x + this.y);
        }
    }

class Class2
    {
        int test;
        Point pt1;
        Point pt2;
        Point pt3;
        List<Point> listPt = new List<Point>() { };

        public Class2()
        {
            test = 100;
            this.pt1 = new Point(2, 3, "red");
            this.pt2 = new Point(1, …
Run Code Online (Sandbox Code Playgroud)

c# reflection casting

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

kotlin DSL 从其他文件中检索密钥

我正在尝试将我的 gradle 文件切换到 Kotlin DSL。我的项目正在调用 API。

build.gradle(app)我有一个函数来检索存储在另一个文件中的 api 密钥keys.properties

在出现一些问题(例如)之后,我重写了函数以获取密钥。我在中编写了以下函数build.gradle.kts

import import java.io.File

fun readFileLineByLineUsingForEachLine2(fileName: String): HashMap<String, String>{
    val items = HashMap<String, String>()

    File(fileName).forEachLine {
        items[it.split("=")[0]] = it.split("=")[1]
    }

    return items
}
Run Code Online (Sandbox Code Playgroud)

然后我设置一个变量来保存特定键的值:

buildConfigField(String!, "API_KEY", returnMapOfKeys()["API_KEY"])
Run Code Online (Sandbox Code Playgroud)

修复了一些错误后,我遇到了以下问题:

app/build.gradle.kts:49:36: Expecting ')'
Run Code Online (Sandbox Code Playgroud)

上面带有buildConfigField.

有人知道这个错误在哪里吗?

或者有人知道如何使用 Kotlin DSL 从文件中检索密钥?

android kotlin build.gradle gradle-kotlin-dsl

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

JavaFx8(+ Maven):加载fxml文件时出错

我正在尝试使用Maven编写JavaFx8应用程序.我写了一个简单的应用程序主类和一个fxml文件(一个什么都不做的root fxml文件).

当我尝试加载fxml根文件时,我收到错误"Location not set":

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:363)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:303)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:875)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(LauncherImpl.java:157)
    at com.sun.javafx.application.LauncherImpl$$Lambda$53/99550389.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Location is not set.
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2428)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2403)
    at org.aklal.todofx.tasks.App.initRootLayout(App.java:58)
    at org.aklal.todofx.tasks.App.start(App.java:31)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(LauncherImpl.java:821)
    at com.sun.javafx.application.LauncherImpl$$Lambda$56/1712616138.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.java:323)
    at com.sun.javafx.application.PlatformImpl$$Lambda$49/1268447657.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:292)
    at …
Run Code Online (Sandbox Code Playgroud)

eclipse maven javafx-8 fxmlloader

0
推荐指数
1
解决办法
5021
查看次数