2016-06-30 3 views
2

recyclerView 내부의 레이아웃 비율을 알 수있는 방법이 있습니까? RecyclerView 내부 팽창화면에 표시되는 RecyclerView 내부 레이아웃의 백분율

레이아웃의 PARAMS있다

android:layout_width="match_parent" android:layout_height="match_parent"

편집 레이아웃 파일을

레이아웃 파일 추가 -

활동 레이아웃 파일 custom_card.xml

<?xml version="1.0" encoding="utf-8"? 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/card" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignBottom="@id/imageView" 
     android:layout_alignTop="@id/imageView" 
     android:scaleType="fitCenter" 
     android:src="@drawable/image_view_screen" /> 

</RelativeLayout> 
합니다.
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
<android.support.v7.widget.RecyclerView 
    android:id="@+id/recyclerView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 
    <ProgressBar 
     android:visibility="gone" 
     android:layout_width="56dp" 
     android:layout_height="56dp" 
     android:id="@+id/progress_bar" 
     android:layout_centerInParent="true"/> 
</RelativeLayout> 

나는 내가 그것을 알아 냈 수직 형 LinearLayoutManager

+0

당신이 당신의 레이아웃의 폭을 얻고, 여기에 높이를 사용하여 예를 –

+0

에 대한 recyclerView의 폭을 비교할 수 있습니다. 레이아웃 높이는 화면에서 볼 수있는 부분이 아니라 원래 크기를 제공합니다. – Harshit

+0

다음은 우리에게 뭔가를 보여줍니다. 스크린 샷? 레이아웃 파일? –

답변

0

후 많은 시도를 사용하고 있습니다. 누군가를 돕는다면.

내 레이아웃 높이가 match_parent 이었기 때문에 더 쉬웠습니다. 그러나이 방법은 일부 계산으로 모든 사람에게 효과적입니다.

int firstItemPos=mLayoutManager.findFirstVisibleItemPosition(); 
View firstItemView=mLayoutManager.findViewByPosition(firstItemPos); 
int lastItemPos=mLayoutManager.findLastVisibleItemPosition(); 
View lastItemView=mLayoutManager.findViewByPosition(lastItemPos); 

이제 firstItemPoslastItemPos 사이의 모든 항목은 100 % 볼 수 있습니다. 마찬가지로 lastItemView-

Math.abs(lastItemView.getY())/lastItemView.getHeight()  
-1

해당 사례 firstItemView-

Math.abs(firstItemView.getY())/firstItemView.getHeight() 

들어

; 어댑터에 ;

private final Rect mCurrentViewRect = new Rect(); 
... your inits... 

onBindViewHolder;

View firstItemView = linearLayoutManager.findViewByPosition(position); 
           int pos= getVisibilityPercents(position); 

이러한 metods를 사용하십시오.

public int getVisibilityPercents(View currentView) { 


    int percents = 100; 

    currentView.getLocalVisibleRect(mCurrentViewRect); 

    int height = currentView.getHeight(); 

    if (viewIsPartiallyHiddenTop()) { 
     percents = (height - mCurrentViewRect.top) * 100/height; 
    } else if (viewIsPartiallyHiddenBottom(height)) { 
     percents = mCurrentViewRect.bottom * 100/height; 
    } 

    return percents; 
} 

private boolean viewIsPartiallyHiddenBottom(int height) { 
    return mCurrentViewRect.bottom > 0 && mCurrentViewRect.bottom < height; 
} 

private boolean viewIsPartiallyHiddenTop() { 
    return mCurrentViewRect.top > 0; 
} 

btw, 귀하의 recyclerView 및 linearLayoutManager를 생성자의 어댑터로 가져 오지 마십시오. 자세한 내용은

=>https://github.com/danylovolokh/VideoPlayerManager

관련 문제