1.二级菜单已展开app列表内,快速按下滚动时焦点跳跃落在底行最后一个item问题
This commit is contained in:
@@ -26,6 +26,7 @@ import android.widget.GridView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
|
||||
@@ -267,28 +268,27 @@ public class Launcher extends FragmentActivity implements SplashView.SplashAdLi
|
||||
gv_shortcut.setCanFocusOutHorizontal(false);
|
||||
gv_shortcut.setCanFocusOutVertical(true);
|
||||
|
||||
StaggeredGridLayoutManager customLayoutManager = new StaggeredGridLayoutManager(9, StaggeredGridLayoutManager.VERTICAL);
|
||||
GridLayoutManager customLayoutManager = new GridLayoutManager(Launcher.this,9);
|
||||
grid_coustom_apps.setLayoutManager(customLayoutManager);
|
||||
grid_coustom_apps.setAdapter(mCustomAppAdapter);
|
||||
|
||||
grid_coustom_apps.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
int childViewPosition=0;
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
View childView = recyclerView.getFocusedChild();
|
||||
childViewPosition= recyclerView.getChildAdapterPosition(childView);
|
||||
LogUtils.loge("childView|childViewPosition==>"+childViewPosition);
|
||||
if(childViewPosition==-1){//当焦点错乱是,强制修正找到目标位置(例如第一个可见项)
|
||||
int[] rows=new int[8];
|
||||
((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPositions(rows);
|
||||
View targetView = recyclerView.findViewHolderForAdapterPosition(rows[0]).itemView;
|
||||
targetView.post(() -> targetView.requestFocus());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
// grid_coustom_apps.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
// int childViewPosition=0;
|
||||
// @Override
|
||||
// public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
// if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
// View childView = recyclerView.getFocusedChild();
|
||||
// childViewPosition= recyclerView.getChildAdapterPosition(childView);
|
||||
// LogUtils.loge("childView|childViewPosition==>"+childViewPosition);
|
||||
// if(childViewPosition==-1){//当焦点错乱是,强制修正找到目标位置(例如第一个可见项)
|
||||
// int[] rows=new int[8];
|
||||
// ((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPositions(rows);
|
||||
// View targetView = recyclerView.findViewHolderForAdapterPosition(rows[0]).itemView;
|
||||
// targetView.post(() -> targetView.requestFocus());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
ADSWindowManager.init(this);
|
||||
bindAdsWindowMultiView();
|
||||
@@ -515,7 +515,29 @@ private void loadShortAppList(){
|
||||
}
|
||||
sortAppList(filteredList);
|
||||
mCustomAppAdapter.addDatas(filteredList);
|
||||
grid_coustom_apps.setAdapter(mCustomAppAdapter);
|
||||
// grid_coustom_apps.setAdapter(mCustomAppAdapter);
|
||||
// if(filteredList.size()>0){
|
||||
// if(Build.VERSION.SDK_INT<29){
|
||||
// grid_coustom_apps.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
// @Override
|
||||
// public void onGlobalLayout() {
|
||||
// grid_coustom_apps.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||
// grid_coustom_apps.scrollToPosition(0);
|
||||
// grid_coustom_apps.post(()->{
|
||||
// int[] rows = new int[9];
|
||||
// ((StaggeredGridLayoutManager) grid_coustom_apps.getLayoutManager()).findFirstVisibleItemPositions(rows);
|
||||
// View targetView = grid_coustom_apps.findViewHolderForAdapterPosition(rows[0]).itemView;
|
||||
// if(targetView!=null){
|
||||
// targetView.post(() -> targetView.requestFocus());
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// }else {
|
||||
// grid_coustom_apps.setSelectedPosition(0);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.view.animation.TranslateAnimation;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
|
||||
|
||||
@@ -18,6 +19,7 @@ import com.android.nebulasdk.presenter.callback.AppnetCallback;
|
||||
import com.android.util.GsonUtil;
|
||||
import com.android.util.LogUtils;
|
||||
import com.ik.mboxlauncher.R;
|
||||
import com.ik.mboxlauncher.ui.Launcher;
|
||||
import com.ik.mboxlauncher.ui.adapter.CustomAppAdapter;
|
||||
import com.ik.mboxlauncher.ui.adapter.VideoAppAdapter;
|
||||
import com.ik.mboxlauncher.ui.adapter.MyAppInfoAdapter;
|
||||
@@ -100,28 +102,28 @@ public abstract class CategoryFragment extends BaseFragment implements AppnetCal
|
||||
}
|
||||
});
|
||||
}
|
||||
StaggeredGridLayoutManager customLayoutManager = new StaggeredGridLayoutManager(8, StaggeredGridLayoutManager.VERTICAL);
|
||||
GridLayoutManager customLayoutManager = new GridLayoutManager(getActivity(),8);
|
||||
grid_coustom_apps.setLayoutManager(customLayoutManager);
|
||||
grid_coustom_apps.setAdapter(mCustomAppAdapter);
|
||||
grid_coustom_apps.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
int childViewPosition=0;
|
||||
@Override
|
||||
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
// 找到目标位置(例如第一个可见项)
|
||||
View childView = recyclerView.getFocusedChild();
|
||||
childViewPosition= recyclerView.getChildAdapterPosition(childView);
|
||||
LogUtils.loge("childView|childViewPosition==>"+childViewPosition);
|
||||
if(childViewPosition==-1){ //当焦点错乱是,强制修正找到目标位置(例如第一个可见项)
|
||||
int[] rows=new int[8];
|
||||
((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPositions(rows);
|
||||
View targetView = recyclerView.findViewHolderForAdapterPosition(rows[0]).itemView;
|
||||
targetView.post(() -> targetView.requestFocus());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
// grid_coustom_apps.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
// int childViewPosition=0;
|
||||
// @Override
|
||||
// public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
||||
// if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||
// // 找到目标位置(例如第一个可见项)
|
||||
// View childView = recyclerView.getFocusedChild();
|
||||
// childViewPosition= recyclerView.getChildAdapterPosition(childView);
|
||||
// LogUtils.loge("childView|childViewPosition==>"+childViewPosition);
|
||||
// if(childViewPosition==-1){ //当焦点错乱是,强制修正找到目标位置(例如第一个可见项)
|
||||
// int[] rows=new int[8];
|
||||
// ((StaggeredGridLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPositions(rows);
|
||||
// View targetView = recyclerView.findViewHolderForAdapterPosition(rows[0]).itemView;
|
||||
// targetView.post(() -> targetView.requestFocus());
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
loadCustomAppList();
|
||||
|
||||
gv_category_apps.setmFocusOnBoundaryListener(new CustomRecyclerViewer.FocusOnBoundaryListener() {
|
||||
|
||||
Reference in New Issue
Block a user