本文整理匯總了Java中android.support.v7.widget.RecyclerView.getLocationOnScreen方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.getLocationOnScreen方法的具體用法?Java RecyclerView.getLocationOnScreen怎麽用?Java RecyclerView.getLocationOnScreen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.getLocationOnScreen方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isChildInCenterX
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* @param recyclerView
* @param view
* @return
*/
public static boolean isChildInCenterX(@NonNull RecyclerView recyclerView, @NonNull View view) {
int childCount = recyclerView.getChildCount();
int[] lvLocationOnScreen = new int[2];
recyclerView.getLocationOnScreen(lvLocationOnScreen);
int middleX = lvLocationOnScreen[0] + recyclerView.getWidth() / 2;
if (childCount > 0) {
int[] vLocationOnScreen = new int[2];
view.getLocationOnScreen(vLocationOnScreen);
int width = view.getWidth();
if (vLocationOnScreen[0] <= middleX && vLocationOnScreen[0] + width >= middleX) {
return true;
}
}
return false;
}
示例2: getInsideLocation
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* 獲取當前點擊的位置在RecyclerView內部的坐標 (Y坐標範圍0+padding到height-padding)?
*/
private float[] getInsideLocation(RecyclerView recyclerView, float touchRawX, float touchRawY) {
float[] result = new float[2];
int[] location = new int[2];
recyclerView.getLocationOnScreen(location);
result[0] = touchRawX - location[0];
result[1] = touchRawY - location[1];
// System.out.println("getInsideLocation:" + result[0] + "-" + result[1] + "==" + "X:" + touchRawX + "Y:" + touchRawY);
result[0] = result[0] / dragListener.getScale();
result[1] = result[1] / dragListener.getScale();
int minY = recyclerView.getPaddingTop();
int maxY = recyclerView.getHeight() - recyclerView.getPaddingBottom();
result[1] = Math.min(Math.max(result[1], minY), maxY);
return result;
}
示例3: addMirrorView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private ImageView addMirrorView(ViewGroup parent, RecyclerView recyclerView, View view) {
view.destroyDrawingCache();
view.setDrawingCacheEnabled(true);
ImageView mirrorView = new ImageView(recyclerView.getContext());
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
mirrorView.setImageBitmap(bitmap);
view.setDrawingCacheEnabled(false);
int[] locations = new int[2];
view.getLocationOnScreen(locations);
int[] parenLocations = new int[2];
recyclerView.getLocationOnScreen(parenLocations);
LayoutParams params = new LayoutParams(bitmap.getWidth(), bitmap.getHeight());
params.setMargins(locations[0], (locations[1] - parenLocations[1]) + UIsUtils.dipToPx(44.0f), 0, 0);
parent.addView(mirrorView, params);
return mirrorView;
}
示例4: addMirrorView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* 添加需要移動的 鏡像View
*/
private ImageView addMirrorView(ViewGroup parent, RecyclerView recyclerView, View view, int[] locations) {
/**
* 我們要獲取cache首先要通過setDrawingCacheEnable方法開啟cache,然後再調用getDrawingCache方法就可以獲得view的cache圖片了。
buildDrawingCache方法可以不用調用,因為調用getDrawingCache方法時,若果cache沒有建立,係統會自動調用buildDrawingCache方法生成cache。
若想更新cache, 必須要調用destoryDrawingCache方法把舊的cache銷毀,才能建立新的。
當調用setDrawingCacheEnabled方法設置為false, 係統也會自動把原來的cache銷毀。
*/
view.destroyDrawingCache();
view.setDrawingCacheEnabled(true);
final ImageView mirrorView = new ImageView(recyclerView.getContext());
Bitmap bitmap = Bitmap.createBitmap(view.getDrawingCache());
mirrorView.setImageBitmap(bitmap);
view.setDrawingCacheEnabled(false);
int[] parenLocations = new int[2];
recyclerView.getLocationOnScreen(parenLocations);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(bitmap.getWidth(), bitmap.getHeight());
params.setMargins(locations[0], locations[1]/* - parenLocations[1]*/, 0, 0);
parent.addView(mirrorView, params);
return mirrorView;
}
示例5: isChildInCenterX
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public static boolean isChildInCenterX(RecyclerView recyclerView, View view) {
int childCount = recyclerView.getChildCount();
int[] lvLocationOnScreen = new int[2];
int[] vLocationOnScreen = new int[2];
recyclerView.getLocationOnScreen(lvLocationOnScreen);
int middleX = lvLocationOnScreen[0] + recyclerView.getWidth() / 2;
if (childCount > 0) {
view.getLocationOnScreen(vLocationOnScreen);
if (vLocationOnScreen[0] <= middleX && vLocationOnScreen[0] + view.getWidth() >= middleX) {
return true;
}
}
return false;
}
示例6: isChildInCenterY
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public static boolean isChildInCenterY(RecyclerView recyclerView, View view) {
int childCount = recyclerView.getChildCount();
int[] lvLocationOnScreen = new int[2];
int[] vLocationOnScreen = new int[2];
recyclerView.getLocationOnScreen(lvLocationOnScreen);
int middleY = lvLocationOnScreen[1] + recyclerView.getHeight() / 2;
if (childCount > 0) {
view.getLocationOnScreen(vLocationOnScreen);
if (vLocationOnScreen[1] <= middleY && vLocationOnScreen[1] + view.getHeight() >= middleY) {
return true;
}
}
return false;
}
示例7: isChildInCenterY
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* @param recyclerView
* @param view
* @return
*/
public static boolean isChildInCenterY(@NonNull RecyclerView recyclerView, @NonNull View view) {
int childCount = recyclerView.getChildCount();
int[] lvLocationOnScreen = new int[2];
recyclerView.getLocationOnScreen(lvLocationOnScreen);
int middleY = lvLocationOnScreen[1] + recyclerView.getHeight() / 2;
if (childCount > 0) {
int[] vLocationOnScreen = new int[2];
view.getLocationOnScreen(vLocationOnScreen);
if (vLocationOnScreen[1] <= middleY && vLocationOnScreen[1] + view.getHeight() >= middleY) {
return true;
}
}
return false;
}
示例8: animate
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void animate(RecyclerView sourceRecycler, RecyclerView targetRecycler, int position) {
View view = sourceRecycler.getLayoutManager().findViewByPosition(position);
if (view == null) {
return;
}
getParentPoint();
mFloatImg_1.setPivotX(mFloatImg_1.getWidth() / 2);
mFloatImg_1.setPivotY(mFloatImg_1.getHeight() / 2);
mFloatImg_1.setVisibility(View.VISIBLE);
int[] initial = new int[2];
view.getLocationOnScreen(initial);
sourceRecycler.getLayoutManager().removeViewAt(position);
BaseMultiAdapter sourceRecyclerAdapter = (BaseMultiAdapter) sourceRecycler.getAdapter();
Filter removedItem = sourceRecyclerAdapter.getItem(position);
int width = view.getWidth();
// view.removeFromParent();
// parent.addView(view)
// view.layoutParams = view.layoutParams.apply {
// this.width = width
// }
int[] container = new int[2];
sourceRecycler.getLocationOnScreen(container);
view.setTranslationX(initial[0] + 0.5f);
view.setTranslationY((initial[1] - container[1]) + 0.5f);
// @Suppress("UNCHECKED_CAST")
SelectIconRvAdapter adapter = (SelectIconRvAdapter) targetRecycler.getAdapter();
int newPos = adapter.add(removedItem);
int[] targetCoordinates = getTarget(targetRecycler, newPos);
float targetX = (targetCoordinates[0] - initial[0]) + 0.5f;
float targetY = (targetCoordinates[1] - initial[1]) + 0.5f;
long duration = calcDuration(targetX, targetY);
animateTranslation(mFloatImg_1, targetX, targetY, duration);
// ObjectAnimator animatorX = ObjectAnimator.ofFloat(mFloatImg_1, "translationX", initial[0], targetCoordinates[0]);
// ObjectAnimator animatorY = ObjectAnimator.ofFloat(mFloatImg_1, "translationY", initial[1] - mStartY, targetCoordinates[1] - mStartY);
// AnimatorSet animatorSet = new AnimatorSet();
// animatorSet.playTogether(animatorX, animatorY);
// animatorSet.setDuration(500);
// animatorSet.start();
// animateAlpha(removedItem, targetRecycler, view, duration)
// animateTranslation(view, deltaX = targetX, deltaY = targetY, duration = duration)
}