小编Peh*_*laj的帖子

OSMDroid:当用户点击地图时添加标记

我想在用户点击地图的地图上显示一个标记。同样,这不应影响双击以进行缩放和/或移动Mapview

我正在使用osmdroid-android-4.0.jar

android osmdroid

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

相机与导航抽屉重叠-Android

伙计们,我需要帮助。看来我的相机活动(是一个片段)与导航抽屉重叠。我不知道该怎么解决。

这是我的样子:

点击这里

这是我的CameraFragment.java代码:

public class CameraFragment extends Fragment {

    private Camera mCamera = null;
    private CameraView mCameraView = null;


    View v;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        v = inflater.inflate(R.layout.activity_first_fragment, container, false);


        try {
            mCamera = Camera.open();//you can use open(int) to use different cameras
        } catch (Exception e) {
            Log.d("ERROR", "Failed to get camera: " + e.getMessage());
        }

        if (mCamera != null) {
            mCameraView = new CameraView(getActivity(), mCamera);//create a SurfaceView to show camera …
Run Code Online (Sandbox Code Playgroud)

java xml android android-camera android-fragments

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

如何在使用改造发送到服务器之前压缩捕获的图像文件大小

我正在使用 Retrofit retrofit:2.1.0' 将文件图像上传到服务器

如果我使用前置摄像头拍摄图像成功上传但如果拍摄后置摄像头它没有上传我认为因为大文件大小的图像没有上传是否有任何选项可以在发送到服务器进行改造之前压缩文件大小?

文件发送编码

  map.put("complaint_category", RequestBody.create(parse("text"), caty_id_str.getBytes()));

    // Map is used to multipart the file using okhttp3.RequestBody
    File file = new File(Config.uriImage);
    // Parsing any Media type file
    RequestBody requestBody = RequestBody.create(parse("*/*"), file);
    MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("photo", file.getName(), requestBody);
    RequestBody filename = RequestBody.create(parse("text/plain"), file.getName());

    Call<PostComplaint> call3 = apiInterface.postComplaint(fileToUpload, filename, map);
    call3.enqueue(new Callback<PostComplaint>() {
        @Override
        public void onResponse(Call<PostComplaint> call, Response<PostComplaint> response) {

            progressDoalog.dismiss();

            PostComplaint respon = response.body();

            PostComplaint.Response respo = respon.getResponse();

            String result = respo.getResult();
            String data = respo.getData(); …
Run Code Online (Sandbox Code Playgroud)

android image-compression retrofit2

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

更改自定义工具栏文本

无法更改我的工具栏上的文本。我已经做了搜索,但是没有结果。

我尝试了很多事情,但也许会弹出。这是我为活动尝试的最后一件事的代码。

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarCustom);
TextView textView = (TextView)   toolbar.findViewById(R.id.toolbarTextView);
textView.setText("String");
Run Code Online (Sandbox Code Playgroud)

这是我的XML代码

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_item_action"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.carson.tryeverything.ItemActionActivity"
android:orientation="vertical"

   >
<android.support.v7.widget.Toolbar
    android:id="@+id/toolbarCustom"
    android:layout_width="match_parent"
    android:layout_height="?actionBarSize"
    android:background="?attr/colorPrimary"
    >

    <TextView
        android:id="@+id/toolbarTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:ellipsize="end"
        android:gravity="center"
        android:maxLines="1"
        android:text="Line one"
          android:textAppearance="@android:style/TextAppearance.WindowTitle"
        android:visibility="visible" />
</android.support.v7.widget.Toolbar>


 <FrameLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"

    >


    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:id="@+id/map"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="4dp"
        android:layout_marginRight="4dp"
        android:layout_marginBottom="6dp"
        android:layout_marginTop="0dp"
        />

  </FrameLayout>

  </LinearLayout>
  android:textAppearance="@android:style/TextAppearance.WindowTitle"
        android:visibility="visible" />
 </android.support.v7.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)

最后是我的清单文件。可能需要一点清洁

 <application
    android:name="android.support.multidex.MultiDexApplication"
    android:allowBackup="true"
    android:icon="@mipmap/icon2"
    android:label="@string/app_name"
    android:supportsRtl="true" …
Run Code Online (Sandbox Code Playgroud)

android textview android-toolbar

5
推荐指数
2
解决办法
6917
查看次数

如何在 Android 中以编程方式启用或禁用蓝牙配置文件?

我有一个要求,其中我有一个通过蓝牙连接到我的手机的配对设备列表。在某些时候,我必须禁用/启用与我的配对设备共享媒体或联系方式。我的要求是在 android 中以编程方式执行此操作。我已经搜索过这个,但找不到任何解决方案。

请告诉我是否可以?

android bluetooth a2dp

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

RecyclerView网格布局管理器不会使项目居中

在此处输入图片说明

我继承了一个带有大量旧代码的大型项目,现在我遇到了一些奇怪的问题。

我需要使此屏幕具有带有网格布局管理器的recyclerview(2列)。这就是我得到的。有没有办法将这些图标放在屏幕中间?我试过重力,但无济于事。可能所有旧代码中都存在问题,或者仅仅是recyclerView的问题?

这是项目的布局(糟糕,请不要问..)

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_view_controller_item_background"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textViewSceneKK"
        android:layout_width="match_parent"
        android:layout_height="@dimen/room_button_height"
        android:layout_gravity="center"
        android:layout_marginLeft="@dimen/row_filter_text_margin_left"
        android:layout_marginRight="@dimen/row_filter_text_margin_left"
        android:gravity="center"
        android:shadowDx="-1"
        android:shadowDy="-1"
        android:shadowRadius="1"
        android:textSize="@dimen/row_scene_kk_text_size" />

    <TextView
        android:id="@+id/textViewSceneName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/row_filter_text_margin_bottom"
        android:layout_marginLeft="@dimen/row_filter_text_margin_left"
        android:layout_marginRight="@dimen/row_filter_text_margin_left"
        android:layout_marginTop="@dimen/row_filter_text_margin_top"
        android:clickable="false"
        android:gravity="center"
        android:longClickable="false"
        android:textColor="@color/main_text_color"
        android:textSize="@dimen/row_browser_right_name_text_size" />
</LinearLayout>

<!--<View-->
<!--android:id="@+id/filterView"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--android:clickable="false"-->
<!--android:longClickable="false" />-->

<View
    android:id="@+id/filterViewClick"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?android:selectableItemBackground"
    android:focusable="false"
    android:focusableInTouchMode="false" />
Run Code Online (Sandbox Code Playgroud)

而不是布局:

<customview.CustomRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none" />
Run Code Online (Sandbox Code Playgroud)

和代码:

 customRecyclerView.setHasFixedSize(false);
    customRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
    customRecyclerView.addItemDecoration(new DividerItemDecoration(getContext(),
            R.drawable.line_separator_empty, DividerItemDecoration.VERTICAL_LIST));

customRecyclerView.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

CustomRecyclerView.java

public class CustomRecyclerView extends RecyclerView …
Run Code Online (Sandbox Code Playgroud)

android gridlayoutmanager android-recyclerview

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

将两个类似的json字段编组到同一个java字段

我有一个示例虚拟JSON响应,如下所示:

    {
        "id": 1,
        "teacher_name": "Foo",
        "teacher_address": "123 Main St.",
        "teacher_phone_num": 1234567891,
        "student_name": "Bar",
        "student_address": "546 Main St.",
        "student_phone_num": 9184248576
    }
Run Code Online (Sandbox Code Playgroud)

以上是一个愚蠢的例子,但它有助于说明我试图使用Jackson将上述内容反序列化为名为"Employee"的Java类:

public class Employee {
    String name;
    String address;
    String phoneNumber;
}
Run Code Online (Sandbox Code Playgroud)

问题是JSON有两个不同的prepends所以我不能在Employee中注释每个字段,并且让对象映射器将teacher_name和student_name映射到Employee对象中的name字段.杰克逊有没有办法指定两个不同名称的节点来映射到同一个Java字段?

java json jackson

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

Eclipse Oxygen:如何指定模块依赖项

我正在尝试熟悉 Eclipse 对 Java 9 模块的支持。我使用 Eclipse Oxygen 以及市场上的 Java 9 支持包和最新的 JDK 9 u180。

问题涉及模块依赖关系以及如何让 Eclipse 了解它们。

我的理解是,在Eclipse中,JPMS模块对应于Eclipse项目。我创建了三个项目(又名模块)并添加了必要的模块信息文件:

module com.effjava.app {
  requires com.effjava.support;
}

module com.effjava.support {
  exports com.effjava.support.hlp;
  exports com.effjava.support.test;
  exports com.effjava.support.user;

  requires transitive com.effjava.util;
}

module com.effjava.util {
  exports com.effjava.util.cbk;
  exports com.effjava.util.reg;
}
Run Code Online (Sandbox Code Playgroud)

这是一个简单的自上而下的依赖链。模块描述符正确;我已经在 IntelliJ 中成功设置了相同的模块。

我的问题是:如何告诉 Eclipse 顶部模块依赖于底部模块,例如中间模块com.effjava.support依赖于底部模块com.effjava.util

我确实在 module-info 文件中指定了依赖关系(通过requires transitive),Eclipse 毫无怨言地接受了该指令。然而,当我编译中间模块时,我看到一条错误消息com.effjava.support。错误消息表明包中的公共类型com.effjava.util.cbk不可见,尽管已由模块导出com.effjava.util并由module com.effjava.support.

显示项目结构和编译器错误消息的屏幕截图

为了指定依赖关系,我将底层模块的内容导出com.effjava.util到一个jar文件中,包括module-info.class。因此它是一个模块化的 jar 文件。

然后我将模块化 jar …

java java-9 eclipse-oxygen

5
推荐指数
0
解决办法
2215
查看次数

无需访问权限和Java密钥即可上传AWS S3

我想将文件上传到S3,而不使用AWS服务器的访问权限和密钥。AWS密钥应作为默认密钥。但是在服务器中运行以下命令,我可以访问它而无需提供任何访问权限和密钥。

aws s3 cp somefile.txt s3:// somebucket /

从Java代码无法访问,因为它无法加载凭据。下面是我的代码。

AmazonS3 s3client = new AmazonS3Client(new DefaultAWSCredentialsProviderChain());
Run Code Online (Sandbox Code Playgroud)

java amazon-s3 amazon-web-services aws-sdk

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

错误:package android support.test不存在

我正在尝试在android studio中构建一个应用程序,我遇到的错误最近才开始出现.据我所知,我没有更改任何设置或修改任何会导致错误发生的系统文件.我已经尝试重新安装android studio但错误仍在发生,所以我开始认为这是一个编码问题.错误如下:

Gradle task[clean, :app:generateDebugSources,:app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :appcompileDebugSources, :app:complieDebugSources, :app: compileDebugAndroidTestSources, :app:compileDebugUnitTestSources]
  C:\Users\Stuart\Documents\TourApp\App\src\androidTest\java\com\example\android\tourapp\ExampleInstrumentedTest.java
error: package android.support.test does not exist
error: package android.support.test.runner does not exist
error: package android org.junit does not exist
error: package android org.junit.runner does not exist
error: package android org.junit does not exist
error: cannot find symbol class RunWith
error: cannot find symbol class Test
error: cannot find symbol variable InstrumentationRegistry
Execution failed for task ':app:compileDebugAndroidTestJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Run Code Online (Sandbox Code Playgroud)

可能导致这种情况的任何想法?

Android Studio错误

android android-studio

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