我有一个set top padding and bottom margin for it的recyclerView:
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.firebase:firebase-database:18.0.0'
implementation 'com.google.android.gms:play-services-ads:18.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.zxing:core:3.3.0'
//compile error code "Wrong 1st argument type. Found:
'com.airvapps.garythebot.StartTutorials', required:
'androidx.fragment.app.FragmentActivity'"
gso = new
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(/*COMPILE ERROR */ this, new
GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull
ConnectionResult connectionResult) {
}
})
.addConnectionCallbacks(new
GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
还有Top Padding:
@Override
protected void directionDownScrolling(View recyclerView) {
MarginLayoutParams params = (MarginLayoutParams) recyclerView.getLayoutParams();
params.setMargins(0, 0, 0,
(int) recyclerView.getContext().getResources().getDimension(R.dimen.dimen_recycler_view_spacing));
mHandler.postDelayed(() -> recyclerView.setLayoutParams(params), 250);
}
如您所见,顶部填充没有延迟,但是我希望在250ms之后出现底部边距,
,但是一旦应用顶部填充,底部边距也会出现。为什么以及如何解决?
答案 0 :(得分:0)
您正在从recyclerView
获取布局参数:
MarginLayoutParams params = (MarginLayoutParams) recyclerView.getLayoutParams();
然后直接在其上设置边距:
params.setMargins(0, 0, 0,
(int) recyclerView.getContext().getResources().getDimension(R.dimen.dimen_recycler_view_spacing));
因此延迟的消息不起作用:
mHandler.postDelayed(() -> recyclerView.setLayoutParams(params), 250);
如果将布局参数设置为其他实例,则将有所不同。而是延迟拨打setMargins
:
@Override
protected void directionDownScrolling(View recyclerView) {
MarginLayoutParams params = (MarginLayoutParams) recyclerView.getLayoutParams();
int marginBottom = (int) recyclerView.getContext().getResources().getDimension(R.dimen.dimen_recycler_view_spacing));
mHandler.postDelayed(() -> {
params.setMargins(0, 0, 0, marginBottom);
recyclerView.requestLayout();
}, 250);
}