1

난에 적어도 단계와 데모 프로젝트를했습니다 RecyclerAdapterConstraintLayout 베타 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)와 테스트를했다

enter image description here

: (오른쪽) (왼쪽) beta-5beta-4를 사용하여

:

결과 RecyclerView 위로 아래로 스 와이프 한 후 StaggeredGridLayoutManagerLinearLayoutManager

이 광고는 Google ()의 문제 보고서와 유사합니다. 210), 누군가가 내가 만든 실수 나 해결 방법을 지적하지 않으면 그 목적을 위해 그 게시물을 사용할 것입니다.

답변

0

문제는 도서관의 마스터 지점에있는 Google이 해결했으며 다음 릴리스 이후에 제대로 작동 할 것입니다.

0

나는 이것이 wrap_content와 함께 beta5의 버그라고 생각합니다. 버그를 신고하고 ConstraintLayout에서 작업하는 Google 엔지니어와상의했습니다. 그는 버그를 확인하고 그것을 재현 한 다음 며칠 후 그는 master에 수정했습니다. 따라서 다음 릴리스 (알 수없는 날짜)로 수정 될 것으로 예상됩니다.

버그 보고서는 here입니다.

2 일 전 현재 Fixed in master.입니다.

+1

나는 문제가 관련이 없다고 생각한다. Google은 20 분 전에 마스터로 합병했습니다. 어쨌든 답장을 보내 주셔서 감사합니다. –