我的布局中有一些TextViews RecyclerView,基于我从Firebase数据库中获取的数据,我使用下面的代码隐藏了一些行,public void Date(String d){ dataRef.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(@NonNull DataSnapshot dataSnapshot) { LatLonConstructor data = dataSnapshot.getValue(LatLonConstructor.class); LatLong = data.getLatLon(); String SplitOldLatlon[] = LatLong.split(" "); Double OldLat = Double.parseDouble(SplitOldLatlon[0]); Double OldLon = Double.parseDouble(SplitOldLatlon[1]); String LatLon1 = location.getText().toString().trim(); String SplitNewLatlon[] = LatLon1.split(" "); Double NewLat = Double.parseDouble(SplitNewLatlon[0]); Double NewLon = Double.parseDouble(SplitNewLatlon[1]); double Theta = NewLon - OldLon; double dist = Math.sin(deg2rad(NewLat)) * Math.sin(deg2rad(OldLat)) + Math.cos(deg2rad(NewLat)) * Math.cos(deg2rad(OldLat)) * Math.cos(deg2rad(Theta)); dist = Math.acos(dist); dist = rad2deg(dist); dist = dist * 60 * 1.1515; String FinalDist = String.valueOf(dist); body.setText(FinalDist); dist = dist * 1.609; if (dist < 1){ int pos = getAdapterPosition(); view.setVisibility(View.GONE); view.setLayoutParams(new RecyclerView.LayoutParams(0,0)); progressDialog.dismiss(); } else { progressDialog.dismiss(); } }现在的问题是它隐藏了视图,但是隐藏元素的地方留下了一个空白区域。我想知道如何正确隐藏RecyclerView的项目。
3 回答
慕村9548890
TA贡献1884条经验 获得超4个赞
有时改变父视图的高度有助于:
view.setVisibility(View.GONE);
view.setLayoutParams(new RecyclerView.LayoutParams(0, 0));
不要忘记恢复行反之亦然:
view.setVisibility(View.VISIBLE);
view.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
希望能帮助到你。
富国沪深
TA贡献1790条经验 获得超9个赞
要添加一些边距来代替该视图,请使视图不可见并根据您的要求设置其宽度。我正在通过 view.GONE 使视图不可见,它不起作用,因为视图不存在,所以要设置什么?。最好的办法就是让它隐形,随心所欲。
linearlayout.setVisibility(View.INVISIBLE); linearlayout.setLayoutParams(new LinearLayoutCompat.LayoutParams(10, 0));
添加回答
举报
0/150
提交
取消