1

공식 "Android Developers"의 this tutorial 다음에 설정 메뉴와 같은 화면의 중심 거리를 기준으로 항목의 크기를 조정하는 RecyclerView을 작성하려고합니다. 이 이미지처럼WearableRecyclerView OffsettingHelper.updateChild()가 작동하지 않습니다.

:

enter image description here

문제는 updateChild() 방법은 전혀 호출되지됩니다 않습니다. 내 오프셋 도우미가 실제로 설정되어 있는지 확인하기 위해 중단 점을 사용하고 updateChild에서 하나 더 확인했지만 모든 설정이 올바르지 만 작동하지는 않습니다.

012 RecyclerOffsettingHelper.java

웨어/build.gradle

compile 'com.google.android.support:wearable:2.0.0' 
compile 'com.google.android.gms:play-services-wearable:10.2.0' 
provided 'com.google.android.wearable:wearable:2.0.0' 

MainActivity.java

mRecyclerView = (WearableRecyclerView) findViewById(R.id.recycler); 

mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false); 
mAdapter = new MainAdapter(this, null); 

mRecyclerView.setLayoutManager(mLayoutManager); 
mRecyclerView.setAdapter(mAdapter); 
mRecyclerView.setCenterEdgeItems(true); 
mRecyclerView.setOffsettingHelper(new RecyclerOffsettingHelper()); 

: 여기

내 코드입니다
public class RecyclerOffsettingHelper extends DefaultOffsettingHelper { 

    /** How much should we scale the icon at most. */ 
    private static final float MAX_ICON_PROGRESS = 0.65f; 

    private float mProgressToCenter; 

    public RecyclerOffsettingHelper() {} 

    @Override 
    public void updateChild(View child, WearableRecyclerView parent) { 
     super.updateChild(child, parent); 

     // Figure out % progress from top to bottom 
     float centerOffset = ((float) child.getHeight()/2.0f)/(float) parent.getHeight(); 
     float yRelativeToCenterOffset = (child.getY()/parent.getHeight()) + centerOffset; 

     // Normalize for center 
     mProgressToCenter = Math.abs(0.5f - yRelativeToCenterOffset); 
     // Adjust to the maximum scale 
     mProgressToCenter = Math.min(mProgressToCenter, MAX_ICON_PROGRESS); 

     child.setScaleX(1 - mProgressToCenter); 
     child.setScaleY(1 - mProgressToCenter); 
    } 
} 

튜토리얼에서 놓친 것이 있습니까? 아니면 잘못 되었습니까? 미리 감사드립니다.

+0

첫 번째 두 요구 사항을 구현하고 관련 XML 레이아웃의 기본 컨테이너로'WearableRecyclerView'를 사용하고'setCenterEdgeItems (boolean)'메소드를'true'로 설정하십시오. 로그가있는 경우 추가 할 수도 있습니다. –

+0

@ Mr.Rebot 예 WearableRecyclerView를 주 컨테이너로 사용하고 추가 한 코드처럼'setCenterEdgeItems (boolean)'을 true로 설정했지만 행운은 없습니다. 그리고 추가 할 중요한 로그 나 오류가 없기를 두려워합니다. ( – Sdghasemi

+0

현재 동일한 문제가 발생 했습니까? – Marc

답변

0

인터넷 검색 및 투쟁의 날이 지나면 나는 이유가 있습니다.

나는 WearableRecyclerView 클래스를 디 컴파일하고 이상하게 LinearLayoutManager을 확장하고 생성자 방법에 재활용보기로 엄격하게 설정됩니다 OffsettingLinearLayoutManager라는 이름의 개인 클래스를 제외하고 setOffsettingHeler() 방법에 의해 설정된 mOffsettingHelper 예를 전혀 사용하는 결과가 없습니다. 따라서 코드에서 레이아웃 관리자를 직접 설정하면 OffsettingHelper는 아무런 도움이되지 않습니다.

은 그래서 해결 방법으로 와서 mOffettingHelper 객체에 updateChide 전화를 scrollVerticallyByonLayoutChildren 메소드를 오버라이드 (override)하는 내 자신의 레이아웃 매니저를 만들었습니다.

public class OffsettingLinearLayoutManager extends LinearLayoutManager { 
    private WearableRecyclerView mWearableRecyclerView; 

    public OffsettingLinearLayoutManager(Context context) { 
     super(context); 
    } 

    public OffsettingLinearLayoutManager(Context context, int orientation, boolean reverseLayout) { 
     super(context, orientation, reverseLayout); 
    } 

    public OffsettingLinearLayoutManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
     super(context, attrs, defStyleAttr, defStyleRes); 
    } 

    public void attachRecyclerView(WearableRecyclerView wearableRecyclerView) { 
     this.mWearableRecyclerView = wearableRecyclerView; 
    } 

    public void detachRecyclerView() { 
     this.mWearableRecyclerView = null; 
    } 

    public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) { 
     int scrolled = super.scrollVerticallyBy(dy, recycler, state); 
     this.updateLayout(); 
     return scrolled; 
    } 

    public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { 
     super.onLayoutChildren(recycler, state); 
     if(this.getChildCount() != 0) { 
      this.updateLayout(); 
     } 
    } 

    private void updateLayout() { 
     if(mWearableRecyclerView != null && mWearableRecyclerView.getOffsettingHelper() != null) { 
      for(int count = 0; count < this.getChildCount(); ++count) { 
       View child = this.getChildAt(count); 
       mWearableRecyclerView.getOffsettingHelper().updateChild(child, mWearableRecyclerView); 
      } 
     } 
    } 
} 

: 여기

내 사용자 정의 LayoutManager의 작업 코드 당신의 WearableRecyclerView 인스턴스를 설정하는 attachRecyclerView 방법을 사용하는 것을 잊지 마십시오.

누군가가 도움이되기를 바랍니다.