1.某个控件要放在Linearlayout布局的底部(底部导航条)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" ...> <LinearLayout android:layout_width="match_parent" android:orientation="vertical" android:layout_height="0dp" android:Layout_weight="2"> ...//嵌套的其他布局…… </LinearLayout> ...//嵌套的其他布局 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> </LinearLayout> </LinearLayout> 简单说明一下,上面的代码中有一个Linearlayout,里面嵌套了两个Linearlayout
这里的关键是嵌套里面的第一个Linearlayout布局,注意这个布局里面的这两行属性代码
`android:layout_height="0dp"` `android:Layout_weight="2"`第二个Linearlayout就是可以放在底部的一个Linearlayout(当然你可以写你自己的布局)
2.RecyclerView显示图片卡顿优化
思路:图片太多,显示卡顿的原因主要是因为在RecyclerView滑动的过程中同时加载网络的图片,所以卡顿。
我们实现滑动的时候不加载网络图片,当不滑动的时候再加载网络图片,这样流畅度就可以提高许多
-
在
RecyclerView的Adapter(自己写的)中添加一个判断RecyclerView是否滑动的boolean变量isScrollingprotected boolean isScrolling = false; public void setScrolling(boolean scrolling) { isScrolling = scrolling; } -
之后在
Adapter里面的onBindViewHolder方法控制加载图片@Override public void onBindViewHolder(ViewHolder holder, int position) { String url = mlist.get(position).getImg().getUrl(); if (!isScrolling){ //我使用的是Ion显示图片框架 //如果不在滑动,则加载网络图片 Ion.with(holder.imageView.getContext()) .load(url) .withBitmap() .placeholder(R.drawable.grey) .intoImageView(holder.imageView); }else { //如果在滑动,就先加载本地的资源图片 Drawable temp = holder.imageView.getResources().getDrawable(R.drawable.grey, null); holder.imageView.setImageDrawable(temp); } } -
在相应的
