小编Sre*_*ree的帖子

在MVP模式中,适配器是否应该包含模型,或者演示者是否应该拥有模型并让适配器引用它?

目前我有它,以便适配器可以引用其中的所有模型.但让演示者只持有模型并且适配器可以简单地引用它们是否更好?

例如:

public class Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

private Presenter presenter;

public Adapter(Presenter presenter){
    this. presenter = presenter;
}

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    Model m = presenter.getModels().get(position);
    // bind model to view holder
}

@Override
public int getItemCount() {
    return presenter.getModels().size();
}


}
Run Code Online (Sandbox Code Playgroud)

这样,当Presenter获取更多模型时,它只是getAdapter().notfiyDataSetChanged();在获取后调用.

mvp android presenter android-adapter

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

ImageView无法正确拉伸图像

所以我不知道为什么会这样.我正在使用Universal Image Loader来加载这些图像.由于一些奇怪的原因,似乎最后一行像素正在被拉伸.我希望图像均匀伸展.(我不在乎它看起来很奇怪.下面的图片仅供演示之用.)

另外,不要介意第一张和最后一张图片.我故意模糊了它,因为它上面有人的脸.

图像看起来像这样 这就是我设置Universal Image Loader的方法:

    //setup Image Loader for loading cruise line logos
    displayImageOptions = new DisplayImageOptions.Builder()
    .showImageOnLoading(R.drawable.ic_launcher)//show this image when image is loading
    .showImageForEmptyUri(R.drawable.ic_launcher)//show this image incase image doesn't exist
    .showImageOnFail(R.drawable.ic_launcher)//show this image if fetching image from URL didn't work
    .cacheInMemory(true)//cache image in RAM
    .cacheOnDisc(true)//cache image in device for later use
    .considerExifParams(true)
    .displayer(new RoundedBitmapDisplayer(5))//super subtle rounded corners on images
    .build();
Run Code Online (Sandbox Code Playgroud)

java android image android-imageview universal-image-loader

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

TextView 在 LinearLayout 中被切断

我正在尝试添加两个不同高度的不同文本视图,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/single_margin"
android:layout_marginLeft="@dimen/double_margin"
android:layout_marginRight="@dimen/double_margin"
android:layout_marginTop="@dimen/single_margin"
android:baselineAligned="false"
android:gravity="center"
android:orientation="horizontal">


<TextView
    android:id="@+id/newsfeed_ad_title"
    android:layout_width="0px"
    android:layout_height="match_parent"
    android:layout_marginRight="28dp"
    android:layout_weight="3"
    android:fontFamily="sans-serif-light"
    android:gravity="center_vertical"
    android:singleLine="false"
    android:text="This is example text view that will mess up the height!"
    android:textColor="@color/dark_blue"
    android:textSize="@dimen/ad_title_text" />


<TextView
    android:id="@+id/newsfeed_ad_info_button"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="2"
    android:background="@drawable/selector_rounded_box_light_blue"
    android:fontFamily="sans-serif-light"
    android:gravity="center"
    android:paddingBottom="@dimen/single_margin"
    android:paddingLeft="@dimen/double_margin"
    android:paddingRight="@dimen/double_margin"
    android:paddingTop="@dimen/single_margin"
    android:text="Learn More"
    android:textColor="@color/dark_blue"
    android:textSize="@dimen/body_text" /> </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

结果是这样的:

在此处输入图片说明

(不要介意上面的阴影。我裁剪了图像,阴影来自操作栏)

线性布局的高度由较小的文本视图而不是较大的文本视图决定。为什么?我该如何修复它?提前致谢

java android textview android-layout android-linearlayout

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

如何在折叠工具栏中将文本视图转换为标题?

我有一个CollapsingToolbarLayout包含a TextView和a RatingBarTextView.是否有可能以TextView某种方式过渡到标题?

我目前的布局如下: 在此输入图像描述

我希望"标题"在工具栏折叠时转换.还会有一个后退按钮,那么我如何确保textview转换到正确的位置(后退按钮的右侧)?

编辑:这是我的XML

<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_view_app_bar_height"
    android:fitsSystemWindows="true"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleTextAppearance="@style/CollapsingToolbarLayoutExpandedTextStyle"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"/>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_marginLeft="@dimen/double_margin"
            android:gravity="center_vertical"
            android:orientation="vertical"
            app:layout_collapseMode="parallax">

            <TextView
                android:id="@+id/title"
                fontPath="fonts/OpenSans-Bold.ttf"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Title"
                android:textColor="@android:color/white"
                android:textSize="@dimen/large_text"/>

            <RatingBar
                android:id="@+id/rating_bar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>

        </LinearLayout>

    </android.support.design.widget.CollapsingToolbarLayout>

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

android android-toolbar android-collapsingtoolbarlayout

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

JsonSerializer 不适用于使用 GSON 的嵌套对象

我有一个 json 对象,如下所示:

{
    "user": {
        "id": 1234
        ... 
        "photos": [
            {
                "url": "http://....."
                ...
            },
            {
                "url": "http://....."
                ...
            }
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

user我想为和编写一个自定义解串器photos

所以我有:

public class User {
    private long id;
    private ArrayList<Photo> photos;
    ... 

    public static class Deserializer implements JsonDeserializer<User> {
        ... // does the custom serialization of the User object 
    }  
}

public class Photo {
    private String url;
    ... 

    public static class Deserializer implements JsonDeserializer<Photos> {
        ... // does the custom serialization …
Run Code Online (Sandbox Code Playgroud)

java serialization android json gson

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

RecyclerView notifyItemRangeInserted不保持滚动位置

我有一个简单的带有项目(技巧)的recyclerview,底部有一个加载微调器。

这是项目计数和项目视图类型方法的外观:

  @Override
  public int getItemViewType(int position) {
    if (position == getItemCount() - 1) { // last position
      return LOADING_FOOTER_VIEW_TYPE;
    }
    else {
      return TIP_VIEW_TYPE;
    }
  }

  @Override
  public int getItemCount() {
    return tips.size() + 1; // + 1 for the loading footer
  }
Run Code Online (Sandbox Code Playgroud)

基本上,我在所有物品下都只有一个加载微调器。

我曾经这样创建适配器:

  public TipsListAdapter(TipsActivity tipsActivity, ArrayList<Tip> tips) {
    this.tipsActivity = tipsActivity;
    this.tips = tips;
  }
Run Code Online (Sandbox Code Playgroud)

然后,一旦我获取了其他项目,就可以像这样调用add:

public void addTips(List<Tip> tips) {

    // hide the loading footer temporarily
    isAdding = true;
    notifyItemChanged(getItemCount() - 1);

    // insert the …
Run Code Online (Sandbox Code Playgroud)

android android-support-library recycler-adapter android-recyclerview recyclerview-layout

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

ColorDrawable占位符无法滑动加载

我在这里做错什么了吗?我想加载该灰色作为占位符,但是它不加载。似乎只有在已经设置或加载了另一个图像的情况下才会发生。

Glide.with(getContext())
    .load(url)
    .placeholder(new ColorDrawable(ContextCompat.getColor(getContext(), R.color.placeholder_gray)))
    .error(new ColorDrawable(ContextCompat.getColor(getContext(), R.color.placeholder_gray)))
    .dontAnimate()
    .into(new SimpleTarget<GlideDrawable>() {
      @Override
      public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
        image.setImageDrawable(resource);
      }

      @Override
      public void onLoadFailed(Exception e, Drawable errorDrawable) {
        resetImageView();
      }
    });
Run Code Online (Sandbox Code Playgroud)

android android-glide

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