난에 적어도 단계와 데모 프로젝트를했습니다 RecyclerAdapter
ConstraintLayout 베타 5 이미지 뷰
에 사용되는 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"
/>
,691 363,210
어댑터는 다음과 같습니다 : 다음과 같이
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 ()의 문제 보고서와 유사합니다. 210), 누군가가 내가 만든 실수 나 해결 방법을 지적하지 않으면 그 목적을 위해 그 게시물을 사용할 것입니다.
나는 문제가 관련이 없다고 생각한다. Google은 20 분 전에 마스터로 합병했습니다. 어쨌든 답장을 보내 주셔서 감사합니다. –