私はへの最小の手順でデモプロジェクトを作ったRecyclerAdapter
ConstraintLayoutベータ5 ImageViewの
で使用ConstraintLayout
内のスケールImageView
を使用しているとき、私は奇妙な行動を観察していcom.android.support.constraint:constraint-layout:1.0.0-beta5
に更新しているので再生:
を行が非常に単純である:ヘッダと画像:
<android.support.constraint.ConstraintLayout 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="wrap_content"
>
<View
android:id="@+id/header"
android:layout_width="0dp"
android:layout_height="10dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<ImageView
android:id="@+id/image"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/header"
/>
アダプタは次のようになります。次のように
public class RecAdapter extends RecyclerView.Adapter<BooleanViewHolder> {
private List<Boolean> list;
public RecAdapter(ArrayList<Boolean> list) {
this.list = list;
}
@Override
public BooleanViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new BooleanViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.row, parent, false));
}
@Override
public void onBindViewHolder(BooleanViewHolder holder, int position) {
holder.header.setBackgroundColor(list.get(position) ? Color.parseColor("#00FF00") : Color.parseColor("#FF0000"));
holder.image.setImageDrawable(null);
if (list.get(position)) {
holder.image.setVisibility(View.VISIBLE);
holder.image.setImageDrawable(holder.image.getContext().getResources().getDrawable(R.drawable.remove_me));
} else {
holder.image.setVisibility(View.GONE);
}
}
@Override
public int getItemCount() {
return list.size();
}
static class BooleanViewHolder extends RecyclerView.ViewHolder {
private final ImageView image;
private final View header;
BooleanViewHolder(View itemView) {
super(itemView);
header = itemView.findViewById(R.id.header);
image = (ImageView) itemView.findViewById(R.id.image);
}
}
}
RecyclerView
及びアダプタが初期化される:
recView = (RecyclerView) findViewById(R.id.recView);
// final StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recView.setLayoutManager(layoutManager);
ArrayList<Boolean> list = new ArrayList<>();
list.add(true);
list.add(false);
list.add(true);
list.add(false);
list.add(true);
list.add(false);
list.add(true);
list.add(false);
recView.setAdapter(new RecAdapter(list));
デモ機能がある: true
もしヘッダが緑に着色され、画像が表示されます。 false
ヘッダーが赤色で、ImageView
が隠れている場合。私は両方を使用してAPI 24 & API 19でテストをした
:(右)(左)beta-5
とbeta-4
を使用して
:
結果RecyclerView上に下にスワイプし、後StaggeredGridLayoutManager
とLinearLayoutManager
私はこれがGoogleの問題レポートのように見えることを知っています(AOSP issue)、しかし私は誰かが私が作った間違いや回避策を指摘しない限り、その目的のためにその投稿を使用します。
私は問題は無関係だと思いますが、似ています。 Googleはこれを20分前と同様にマスターに統合しました。とにかく返信してくれてありがとう –