小编Nil*_*kar的帖子

停止Exoplayer onSwipe of ViewPager

我正在使用ViewPager单片段实例,其中我显示Media图像,视频,音频等文件.

我已经实现ExoPlayer了处理VideoAudio文件.而Glide对于图像.

这里避免内存泄漏我发布这样的ExoPlayer对象ItemViewerFragment.java:

 private void releasePlayer() {
        if (player != null) {
            player.release();
            player = null;
            trackSelector = null;
            simpleExoPlayerView.setPlayer(null);
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        if (player == null && currentGalleryModel != null) {
            initializePlayer();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        if (player == null && currentGalleryModel != null) {
            initializePlayer();
        }
    }

    @Override
    public void onPause() …
Run Code Online (Sandbox Code Playgroud)

java android android-viewpager exoplayer

15
推荐指数
2
解决办法
2916
查看次数

当代码为401时,如何在okhttp中获取响应体

我正在使用okHttp 3.2.0,这里是构建请求对象的代码

MediaType JSON = MediaType.parse(AppConstants.CONTENT_TYPE_VALUE_JSON);
RequestBody body = RequestBody.create(JSON, requestBody);


    HttpUrl url = new HttpUrl.Builder()
                                    .scheme("http")
                                    .host("192.168.0.104")
                                    .port(8080)
                                    .addPathSegment("mutterfly-server")
                                    .addPathSegment("j_spring_security_check")
                                    .addQueryParameter("j_username", jsonObject.getString("emailId"))
                                    .addQueryParameter("j_password", jsonObject.getString("password"))
                                    .build();

     request = new Request.Builder()
                                    .addHeader(AppConstants.CONTENT_TYPE_LABEL, AppConstants.CONTENT_TYPE_VALUE_JSON)
                                    .addHeader(AppConstants.ACCEPT_LABEL, AppConstants.CONTENT_TYPE_VALUE_JSON)
                                    .url(url)
                                    .post(body)
                                    .build();
Run Code Online (Sandbox Code Playgroud)

以下是我如何解析响应

client.newCall(request).enqueue(new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {

                }

                @Override
                public void onResponse(Call call, final Response response) throws IOException {

                    String respBody;
                    if (response.isSuccessful()) {
                        if (response.body() != null) {
                            respBody = response.body().string();
                            Log.i(TAG, respBody);
                            response.body().close();
                            if (AppMethods.checkIfNull(loginParserListener)) { …
Run Code Online (Sandbox Code Playgroud)

android okhttp okhttp3

9
推荐指数
2
解决办法
6244
查看次数

OnRatingBarChangeListener中的Android Nougat(7.0/API 24)评级计数错误

RatingBar在Android Nougat(7.0)中使用并OnRatingBarChangeListener用于检测评级变化.

它在回调方法中给出了错误的评级值.所以假设如果我点击第二颗星它给我3.0,如果我点击第四颗星它给我数为5.0.

我注意到的另一件事是数量取决于我点击的确切位置.如果我点击星的前半部分它返回正确的计数,如果我点击星的后半部分,它会增加+1来计数.

视频链接

活动:

RatingBar ratingBar = (RatingBar) findViewById(R.id.ratingBar2);

    ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
      @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {

        Log.i(TAG, String.format("Rating is %f : fromUser %b", rating, fromUser));

        mTextView.setText(String.format("Rating is %f ", rating));
      }
    });
Run Code Online (Sandbox Code Playgroud)

XML:

  <RatingBar
      android:id="@+id/ratingBar2"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:isIndicator="false"
      android:stepSize="1"
      android:rating="5"
      />
Run Code Online (Sandbox Code Playgroud)

android ratingbar

9
推荐指数
1
解决办法
1005
查看次数

使用okhttp3集成java.lang.NoClassDefFoundError滑行

我正在使用okhttp3滑行,所以我也添加了集成部分.

compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.github.bumptech.glide:okhttp-integration:1.4.0@aar'
Run Code Online (Sandbox Code Playgroud)

我甚至使用了multidex支持

compile 'com.android.support:multidex:1.0.1'
Run Code Online (Sandbox Code Playgroud)

并将其添加到应用程序类

 @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(base);
    }
Run Code Online (Sandbox Code Playgroud)

这是完整的堆栈跟踪 -

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/squareup/okhttp/OkHttpClient;
at com.bumptech.glide.integration.okhttp.OkHttpUrlLoader$Factory.getInternalClient(OkHttpUrlLoader.java:30)
at com.bumptech.glide.integration.okhttp.OkHttpUrlLoader$Factory.<init>(OkHttpUrlLoader.java:41)
at com.bumptech.glide.integration.okhttp.OkHttpGlideModule.registerComponents(OkHttpGlideModule.java:31)
at com.bumptech.glide.Glide.get(Glide.java:157)
at com.bumptech.glide.RequestManager.<init>(RequestManager.java:62)
at com.bumptech.glide.RequestManager.<init>(RequestManager.java:53)
at com.bumptech.glide.manager.RequestManagerRetriever.supportFragmentGet(RequestManagerRetriever.java:198)
at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:104)
at com.bumptech.glide.Glide.with(Glide.java:644)
at com.skcsllp.mutterfly.activities.EditProfileActivity.onCreate(EditProfileActivity.java:76)
at android.app.Activity.performCreate(Activity.java:6100)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2601)
at android.app.ActivityThread.access$800(ActivityThread.java:178)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5637)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)


    Caused by: java.lang.ClassNotFoundException: Didn't find class …
Run Code Online (Sandbox Code Playgroud)

android android-glide okhttp3

6
推荐指数
1
解决办法
4252
查看次数

文字包装在两行 - recyclerview

我正在设计具有预期UI的应用程序

预期

我正在使用RecyclerView

StaggeredGridLayoutManager manager=new StaggeredGridLayoutManager(3,1);
        recyclerView.setLayoutManager(manager);
Run Code Online (Sandbox Code Playgroud)

这是行xml文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/padding_8dp"
    android:layout_marginLeft="@dimen/padding_4dp"
    android:layout_marginRight="@dimen/padding_4dp"
   >

    <com.skcsllp.mutterfly.views.widgets.MfTextView
        android:id="@+id/tagName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/textview"
        android:layout_gravity="center_horizontal"
        android:gravity="center"
        android:textSize="@dimen/text_18"

        android:background="@drawable/selector_tags"
        android:textColor="@color/tags_text_color"

        />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

使用这么多我得到的输出

我得到了什么

我不希望标签进入第二行.我知道我已经使用跨度计数为3,因此在一行中获得3个标签,但有没有办法避免文本换行在两行?

android textview android-recyclerview

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