Android 使用湿壁画将局部图像加载到RecyclerView时,它';It’不顺利
原因可能是我的本地图像太大,但不可能缩放手机中的每个图像。我能做些什么来解决这个问题 item.xmlAndroid 使用湿壁画将局部图像加载到RecyclerView时,它';It’不顺利,android,Android,原因可能是我的本地图像太大,但不可能缩放手机中的每个图像。我能做些什么来解决这个问题 item.xml <?xml version="1.0" encoding="utf-8"?> <layout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <data>
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="item"
type="com.appbaba.digital.test.Test"/>
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/simpleDraweeView"
android:layout_width="90dp"
android:layout_height="90dp"
app:actualImageScaleType="centerCrop"
app:placeholderImage="@mipmap/ic_place_holder"
app:placeholderImageScaleType="centerCrop"
app:progressBarAutoRotateInterval="3000"
app:progressBarImage="@mipmap/ic_progress"
app:progressBarImageScaleType="centerCrop"/>
</FrameLayout>
</layout>
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data
class=".PhotoWallBinding"
></data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/theme_primary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cl_bg_gravy"
android:orientation="vertical">
<include layout="@layout/title_bar"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</FrameLayout>
</layout>
recyclerView.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="item"
type="com.appbaba.digital.test.Test"/>
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/simpleDraweeView"
android:layout_width="90dp"
android:layout_height="90dp"
app:actualImageScaleType="centerCrop"
app:placeholderImage="@mipmap/ic_place_holder"
app:placeholderImageScaleType="centerCrop"
app:progressBarAutoRotateInterval="3000"
app:progressBarImage="@mipmap/ic_progress"
app:progressBarImageScaleType="centerCrop"/>
</FrameLayout>
</layout>
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data
class=".PhotoWallBinding"
></data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/theme_primary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cl_bg_gravy"
android:orientation="vertical">
<include layout="@layout/title_bar"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</FrameLayout>
</layout>
JavaCode
public class PhotoWallAty extends BaseAty<String> {
private PhotoWallBinding photoWallBinding;
private RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
photoWallBinding = (PhotoWallBinding) viewDataBinding;
}
@Override
protected void initViews() {
defaultTitleBar(this).setTitle("Albumn");
recyclerView = photoWallBinding.recyclerView;
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
commonBinderAdapter.setIsScrolling(false);
} else {
commonBinderAdapter.setIsScrolling(true);
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
}
});
fillLatestImagePaths();
commonBinderAdapter = new CommonBinderAdapter<String>(this, R.layout.item_test, list) {
@Override
public void onBind(ViewDataBinding viewDataBinding, CommonBinderHolder holder, int
position, String s) {
ItemTestBinding itemTestBinding = (ItemTestBinding) viewDataBinding;
itemTestBinding.simpleDraweeView.setImageURI(Uri.parse("file://" + s));
}
};
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3, LinearLayoutManager
.VERTICAL, true);
recyclerView.setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(commonBinderAdapter);
}
@Override
protected void initEvents() {
}
@Override
protected int getContentView() {
return R.layout.aty_photo_wall;
}
@Override
protected void onClick(int id, View view) {
}
private void fillLatestImagePaths() {
list.clear();
AppTools.showLoadingDialog(this);
new Thread(new Runnable() {
@Override
public void run() {
int maxCount = 30;
Uri mImageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String key_MIME_TYPE = MediaStore.Images.Media.MIME_TYPE;
String key_DATA = MediaStore.Images.Media.DATA;
Cursor cursor = getContentResolver().query(mImageUri, new String[]{key_DATA},
key_MIME_TYPE + "=? or " + key_MIME_TYPE + "=? or " + key_MIME_TYPE +
"=?", new
String[]{"image/png", "image/jpg", "image/jpeg"}, MediaStore
.Images.Media
.DATE_MODIFIED);
if (cursor.moveToLast()) {
while (true) {
String path = cursor.getString(0);
if (!list.contains(path))
list.add(path);
if (list.size() > maxCount || !cursor.moveToPrevious()) {
break;
}
}
}
handler.sendEmptyMessage(0);
}
}).start();
}
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case 0:
AppTools.dismissLoadingDialog();
LogTools.e(list.get(0));
commonBinderAdapter.notifyDataSetChanged();
break;
}
}
};
}
公共类PhotoWallAty扩展了BaseAty{
私人照相墙装订;照相墙装订;
私人回收站;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
photoWallBinding=(photoWallBinding)视图数据绑定;
}
@凌驾
受保护的void initViews(){
defaultTitleBar(this).setTitle(“唱片集”);
recyclerView=photoWallBinding.recyclerView;
recyclerView.addOnScrollListener(新的recyclerView.OnScrollListener(){
@凌驾
CrollStateChanged上的公共无效(RecyclerView RecyclerView,int newState){
super.onScrollStateChanged(recyclerView、newState);
if(newState==RecyclerView.SCROLL\u STATE\u IDLE){
commonBinderAdapter.SetIsCrolling(假);
}否则{
commonBinderAdapter.SetIsCrolling(真);
}
}
@凌驾
已填空的公共空间(RecyclerView RecyclerView、int dx、int dy){
super.onScrolled(recyclerView、dx、dy);
}
});
filllatestimagepath();
commonBinderAdapter=新的commonBinderAdapter(此,R.layout.item_测试,列表){
@凌驾
public void onBind(ViewDataBinding ViewDataBinding,CommonBinderHolder holder,int
位置,字符串s){
ItemTestBinding ItemTestBinding=(ItemTestBinding)viewDataBinding;
itemTestBinding.SimpleDraweView.setImageURI(Uri.parse(“文件:/”+s));
}
};
GridLayoutManager GridLayoutManager=新的GridLayoutManager(此,3,LinearLayoutManager
垂直的,真实的);
setLayoutManager(gridLayoutManager);
recyclerView.setAdapter(commonBinderAdapter);
}
@凌驾
受保护的void initEvents(){
}
@凌驾
受保护的int getContentView(){
返回R.layout.aty_照片_墙;
}
@凌驾
受保护的void onClick(int-id,视图){
}
私有void fillLatestImagePaths(){
list.clear();
AppTools.showLoadingDialog(此);
新线程(newrunnable()){
@凌驾
公开募捐{
int maxCount=30;
Uri mimageri=MediaStore.Images.Media.EXTERNAL\u CONTENT\u Uri;
String key_MIME_TYPE=MediaStore.Images.Media.MIME_TYPE;
字符串key_DATA=MediaStore.Images.Media.DATA;
Cursor Cursor=getContentResolver().query(mimageri,新字符串[]{key_DATA},
按键MIME类型+“=”或“+按键MIME类型+”=?或“+按键MIME类型”+
“=?”,新
字符串[]{“image/png”、“image/jpg”、“image/jpeg”},MediaStore
.Images.Media
.修改日期);
if(cursor.moveToLast()){
while(true){
字符串路径=cursor.getString(0);
如果(!list.contains(路径))
添加(路径);
if(list.size()>maxCount | |!cursor.moveToPrevious()){
打破
}
}
}
handler.sendEmptyMessage(0);
}
}).start();
}
私有处理程序=新处理程序(){
@凌驾
公共无效handleMessage(消息消息消息){
超级handleMessage(msg);
开关(msg.what){
案例0:
AppTools.dismissLoadingDialog();
LogTools.e(list.get(0));
commonBinderAdapter.notifyDataSetChanged();
打破
}
}
};
}
适配器
public abstract class CommonBinderAdapter<T> extends RecyclerView.Adapter<CommonBinderHolder> {
protected Context context;
protected List<T> list;
protected int resId;
protected BinderOnItemClickListener listener;
protected CommonBinderHolder holder;
protected Integer[] layouts = null;
//Single layout
public CommonBinderAdapter(Context context, int resId, List<T> list) {
this.context = context;
this.list = list;
this.resId = resId;
}
//Multiple layout
public CommonBinderAdapter(Context context, List<T> list, Integer... layouts) {
this.context = context;
this.list = list;
this.layouts = layouts;
}
public CommonBinderAdapter(List<T> list) {
this.list = list;
}
@Override
public CommonBinderHolder onCreateViewHolder(ViewGroup parent, int viewType) {
ViewDataBinding binding;
binding = DataBindingUtil.inflate(LayoutInflater.from(context), resId,
parent, false);
holder = new CommonBinderHolder(binding, binding.getRoot(), listener);
return holder;
}
@Override
public void onBindViewHolder(CommonBinderHolder holder, int position) {
onBind(holder.getBinding(), holder, position, list.get(position));
}
public abstract void onBind(ViewDataBinding viewDataBinding, CommonBinderHolder holder, int
position, T t);
@Override
public int getItemCount() {
return list.size();
}
public void setBinderOnItemClickListener(BinderOnItemClickListener listener) {
if (listener != null)
this.listener = listener;
}
public CommonBinderHolder getHolder() {
return holder;
}
}
公共抽象类CommonBinderAdapter扩展了RecyclerView.Adapter{
受保护的语境;
受保护名单;
受保护的int剩余物;
受保护的BinderOnItemClickListener侦听器;
受保护的普通活页夹持器;
受保护整数[]布局=空;
//单一布局
公共CommonBinderAdapter(上下文上下文、int resId、列表){
this.context=上下文;
this.list=列表;
这个。剩余=剩余;
}
//多重布局
公共CommonBinderAdapter(上下文上下文、列表、整数…布局){
this.context=上下文;
this.list=列表;
这个布局=布局;
}
公共CommonBinderAdapter(列表){
this.list=列表;
}
@凌驾
公共CommonBinderHolder onCreateViewHolder(视图组父级,int-viewType){
视图数据绑定;
binding=DataBindingUtil.inflate(布局)flater.from(上下文),resId,
父母,假);
holder=newcommonbinderholder(binding,binding.getRoot(),listener);
报税表持有人;
}
@凌驾
BindViewHolder上的公共无效(CommonBinderHolder holder,int位置){
onBind(holder.getBinding(),holder,position,list.get(position));
}
公共抽象void onBind(ViewDataBinding ViewDataBinding,CommonBinderHolder holder,int
位置(T);
@凌驾
public int getItemCount(){
返回list.size();
}
公共void setBinderOnItemClickListener(BinderOnItemClickListener侦听器){
if(侦听器!=null)