0:
NestedScrollView里面包含recyclerView时,recyclerView里的item高度要是wrap_content,若是match_parent,item显示会有问题
1:
动态设置 android:layout_marginTop。
LinearLayout.LayoutParams layoutParam = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
layoutParam.setMargins(0, 20, 0, 0);
xxxLayout.setLayoutParams(layoutParam);
其中,LinearLayout是看xxxLayout的父布局是哪个布局,若父布局是FrameLayout,则改成FrameLayout。
setMargins参数,可以点方法进去查看,单位是px。
dp转px:
/**
* 根据手机的分辨率从 dp 的单位 转成为 px(像素)
*/
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
px转dp:
/**
* 根据手机的分辨率从 px(像素) 的单位 转成为 dp
*/
public static int px2dip(Context context, float pxValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (pxValue / scale + 0.5f);
}
2:
RecyclerView下拉刷新item间距变大的问题
if (recyclerView.getItemDecorationCount() == 0 ) {//加个判断
recyclerView.addItemDecoration(gridItemDecoration);
}
RecyclerView刷新ItemDecorations间距不断增加问题的处理
3:
TabLayout 自定义指示线tabIndicator
4:
页面有可滑动的recycleview和最下面的确定按钮
参考NestedScrollView被底部View遮挡的问题
5: RelativeLayout水平居中:android:layout_centerHorizontal="true"
垂直居中:android:layout_centerVertical="true"
水平垂直都居中android:layout_centerInParent="true"(也可以上面2个全部写)
距离右边 :android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/dp_20"
LinearLayout居中:android:layout_gravity="center_vertical" android:gravity="center_vertical"
水平垂直都居中:android:gravity="center"(LinearLayout里面加)
(https://blog.csdn.net/qq_41760521/article/details/83176704)
6:textview旁边加上图片。
xml:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="18dp"
android:drawablePadding="6dp"
android:drawableRight="@mipmap/ico_dianzan"
android:gravity="center_vertical"
android:text="0"
android:textSize="12sp"/>
java:
if (datas.get(position).isPraised()) {
Drawable drawable = mContext.getResources().getDrawable(R.mipmap.ico_dianzan_selected);
// 这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
favort.setCompoundDrawables(null, null, drawable, null);
} else {
Drawable drawable = mContext.getResources().getDrawable(R.mipmap.ico_dianzan);
// 这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
favort.setCompoundDrawables(null, null, drawable, null);
}
(https://blog.csdn.net/jky_yihuangxing/article/details/78490730)
7:android:divider的属性可以把分割线加好几种位置,showDividers="middle"
app:cardElevation="0dp"可以去掉CardView的边框线
8:recycleview里面的item抢占焦点,导致一进去就自动滑动偏移的情况,在recycleview里面加上
android:descendantFocusability="blocksDescendants"
https://blog.csdn.net/github_38114833/article/details/100887500
9:做标签页的时候,recycleview设置了一个item,但是加载出来一直有个空白,而且还和item的高度一样,最后发现,recycleview里面加了一个 app:spanCount="2"的属性,这样的话,recycleview默认有2个item,所以才出现一个空白item
10:有时候需要隐藏recycleview的一个item,设置了gone,但是位置还在,显示空白。
需要改变他的高度才行:
ViewGroup.LayoutParams layoutParams = linearLayout.getLayoutParams();
if (receptionHallBeanList.size()==0){
//隐藏item要把高度宽度设为0;
linearLayout.setVisibility(View.GONE);
layoutParams.height = 0;
layoutParams.width = 0;
}else {
//显示item要重新设置高度宽度;
linearLayout.setVisibility(View.VISIBLE);
layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
}
linearLayout.setLayoutParams(layoutParams);
https://blog.csdn.net/wuqingsen1/article/details/79698749
11:RelativeLayout里面设置了一个CardView,发现挡住了CardView下面的布局,需要把CardView的cardElevation属性设置为0
https://www.jianshu.com/p/b9b40690a5e7
12:NestedScrollView 嵌套 RecyclerView 导致RecyclerView跳转到顶部失效。
用nested_scrollview.fullScroll(View.FOCUS_UP);
https://blog.csdn.net/cmzblack/article/details/105433669
13:imageview设置圆角
RoundedCorners roundedCorners = new RoundedCorners(5);圆角为5
RequestOptions options = RequestOptions.bitmapTransform(roundedCorners);
Glide.with(this)
.load(list.get(position).getImage())
.apply(options)
.into(holder.mUrl);
https://blog.csdn.net/weixin_43117800/article/details/107382674
14:ImageView的scaleType设置不当,导致使用Glide时出现OOM
http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0606/3002.html
15:recycleview外层加一个ScrollView,会一次性加载所有item
https://www.imooc.com/wenda/detail/559995
16:RecyclerView让置顶项置顶
直接使用recyclerView的scrollToPosition/smoothScrollToPosition只能让指定项显示出来,并非置顶。网络上的大多方法都是冗余方法,其实google直接提供了方法
linearLayoutManager = new LinearLayoutManager(activity);
postDetailsRecyclerView.setLayoutManager(linearLayoutManager);
linearLayoutManager.scrollToPositionWithOffset(position,0);///核心调用语句
就是使用Recycleview的LinearLayoutManager的scrollToPositionWithOffset()即可
https://blog.csdn.net/chxc_yy/article/details/102929077?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_title~default-0.control&spm=1001.2101.3001.4242
https://www.jianshu.com/p/1633ea5a3939
https://www.jianshu.com/p/3acc395ae933
17:RecyclerView加载多布局界面上移(抢占焦点)
recyview里面加上android:descendantFocusability="blocksDescendants"
https://blog.csdn.net/github_38114833/article/details/100887500