在Android marshmallow

时间:2018-02-03 05:41:58

标签: android android-layout android-studio android-gridview

我有网格视图,图像有两列,网格视图完美显示在android marshmallow,而当我在android nougat尝试它只显示进度条,甚至没有占位符显示在Android牛轧糖。请告诉我,它有什么问题。如何解决它。 以下是我的代码

  

这是滑翔依赖   编译' com.github.bumptech.glide:滑翔:3.7.0   activity_profile.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.vijay.newroot.ProfileActivity">
   <ProgressBar
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:id="@+id/progress_bar"
       android:layout_centerHorizontal="true"
       />
   <GridView
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:numColumns="auto_fit"
       android:gravity="center"
       android:layout_below="@+id/progress_bar"
       android:verticalSpacing="1dp"
       android:horizontalSpacing="1dp"
       android:stretchMode="columnWidth"
       android:id="@+id/profileList">
      </GridView>
      </RelativeLayout>
  

card_view.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
    <ImageView
   android:layout_width="190dp"
   android:layout_height="190dp"
   android:src="@drawable/fb_avatar"
   android:id="@+id/imageId"/>
   </RelativeLayout>
  

ProfileActivity.java

    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.Context;
    import android.content.Intent;
    import android.media.Image;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.support.v7.widget.GridLayoutManager;
    import android.support.v7.widget.LinearLayoutManager;
    import android.support.v7.widget.RecyclerView;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.GridView;
    import android.widget.ImageView;
    import android.widget.ListAdapter;
    import android.widget.ProgressBar;
    import android.widget.Toast;

    import com.bumptech.glide.Glide;
     import com.bumptech.glide.load.engine.DiskCacheStrategy;
     import com.bumptech.glide.load.resource.drawable.GlideDrawable;
     import com.bumptech.glide.request.RequestListener;
     import com.bumptech.glide.request.target.Target;
     import com.firebase.ui.database.FirebaseListAdapter;
     import com.firebase.ui.database.FirebaseRecyclerAdapter;
     import com.google.firebase.auth.FirebaseAuth;
     import com.google.firebase.database.DataSnapshot;
     import com.google.firebase.database.DatabaseError;
     import com.google.firebase.database.DatabaseReference;
     import com.google.firebase.database.FirebaseDatabase;
     import com.google.firebase.database.Query;
     import com.google.firebase.database.ValueEventListener;
     import com.squareup.picasso.Callback;
     import com.squareup.picasso.NetworkPolicy;
     import com.squareup.picasso.Picasso;

    import java.util.ArrayList;

     public class ProfileActivity extends AppCompatActivity {
     GridView profileGrid;
     DatabaseReference databaseReference;
     FirebaseAuth mAuth;
     String uid;
     FirebaseHelper helper;
     CustomAdapter adapter;
     ProgressBar progressBar;

     @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
    databaseReference = FirebaseDatabase.getInstance().getReference().child("Blog");
    helper=new FirebaseHelper(databaseReference);
    profileGrid = (GridView) findViewById(R.id.profileList);
    progressBar= (ProgressBar)findViewById(R.id.progress_bar);
    mAuth=FirebaseAuth.getInstance();
    adapter=new CustomAdapter(this, helper.retrieve(),helper.fetchKey(),progressBar);

    profileGrid.setAdapter(new CustomAdapter(this,helper.retrieve(),helper.fetchKey(),progressBar));


      }

     }


   class CustomAdapter extends BaseAdapter {
   Context c;
ArrayList<Blog> spacecrafts;
ArrayList<String> post_Key;
ProgressBar progress;
public CustomAdapter(Context c, ArrayList<Blog> spacecrafts,ArrayList<String>post_Key,ProgressBar progressBar) {
    this.c = c;
    this.spacecrafts = spacecrafts;
    this.post_Key=post_Key;
    progress=progressBar;
}

@Override
public int getCount() {
    return spacecrafts.size();
}

@Override
public Object getItem(int position) {
    return spacecrafts.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if(convertView==null)
    {
        convertView= LayoutInflater.from(c).inflate(R.layout.card_view,parent,false);

    }

    final ImageView imageView= (ImageView) convertView.findViewById(R.id.imageId);
    imageView.setLayoutParams(new GridView.LayoutParams(85,85));
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    final Blog s= (Blog) this.getItem(position);
    final String key=post_Key.get(position);
    progress.setVisibility(View.VISIBLE);
    Toast.makeText(c,"Up",Toast.LENGTH_SHORT).show();
                Glide.with(c).load(s.getImage()).thumbnail(0.5f).crossFade().fitCenter().placeholder(R.drawable.fb_avatar).diskCacheStrategy(DiskCacheStrategy.ALL).listener(new RequestListener<String, GlideDrawable>() {
        @Override
        public boolean onException(Exception e, String model,     Target<GlideDrawable> target, boolean isFirstResource) {

            Toast.makeText(c,"error",Toast.LENGTH_SHORT).show();
            return false;
        }

        @Override
        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {

            return false;
        }
    }).into(imageView);
    Toast.makeText(c,"Down",Toast.LENGTH_SHORT).show();
    progress.setVisibility(View.GONE);
    convertView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent=new Intent(c,BlogSingleActivity.class);
            intent.putExtra("blog_id",key);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            c.startActivity(intent);


        }
    });

    return convertView;
   }


  }

  class FirebaseHelper {

DatabaseReference db;
Boolean saved=null;
ArrayList<Blog> spacecrafts=new ArrayList<>();
ArrayList<String>postkeys=new ArrayList<>();
FirebaseAuth mAuth;
public FirebaseHelper(DatabaseReference db) {
    this.db = db;
    mAuth=FirebaseAuth.getInstance();
}

//IMPLEMENT FETCH DATA AND FILL ARRAYLIST

//READ BY HOOKING ONTO DATABASE OPERATION CALLBACKS
public ArrayList<Blog> retrieve() {
    db.orderByChild("uid").equalTo(mAuth.getCurrentUser().getUid().toString()).addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            spacecrafts.clear();
            for(DataSnapshot dataSnapshot1:dataSnapshot.getChildren()){
                Blog blog=dataSnapshot1.getValue(Blog.class);
                String key=dataSnapshot1.getKey();
                spacecrafts.add(blog);

            }
        }
        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

    return spacecrafts;
}
 public ArrayList<String> fetchKey(){
     db.orderByChild("uid").equalTo(mAuth.getCurrentUser().getUid()).addValueEventListener(new ValueEventListener() {
         @Override
         public void onDataChange(DataSnapshot dataSnapshot) {
             postkeys.clear();
             for(DataSnapshot dataSnapshot1:dataSnapshot.getChildren()) {
                 String key = dataSnapshot1.getKey();
                 postkeys.add(key);
             }
         }

         @Override
         public void onCancelled(DatabaseError databaseError) {

         }
     });
     return postkeys;
 }
  }

0 个答案:

没有答案