Android 应用程序从Firebase数据库获取图像时,预定义图像不会显示

Android 应用程序从Firebase数据库获取图像时,预定义图像不会显示,android,image,facebook,firebase,firebase-realtime-database,Android,Image,Facebook,Firebase,Firebase Realtime Database,这不是一个真正的问题,但我一直在寻找做的是,让cardview显示我在我的cardview中设置的图像,而应用程序从firebase数据库服务器获取图像。与大多数应用程序一样,例如Facebook(cardview中的图像在从服务器获取数据之前显示空白图片) 现在,我的应用程序所做的是,除非应用程序未联机连接或获取数据,否则cardview将收缩到wrap_内容大小。我正在添加图像,它将清除问题的透视图 当数据提取完成时,它如下所示: 现在,我将我的xml文件发送给用户,在该文件中,我自己的

这不是一个真正的问题,但我一直在寻找做的是,让cardview显示我在我的cardview中设置的图像,而应用程序从firebase数据库服务器获取图像。与大多数应用程序一样,例如Facebook(cardview中的图像在从服务器获取数据之前显示空白图片)

现在,我的应用程序所做的是,除非应用程序未联机连接或获取数据,否则cardview将收缩到wrap_内容大小。我正在添加图像,它将清除问题的透视图

当数据提取完成时,它如下所示:

现在,我将我的xml文件发送给用户,在该文件中,我自己的图像将为用户提供,直到图像从服务器获取为止

1.fragment\u blog.xml

<FrameLayout 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"
tools:context="com.example.aadarshkumarsingh.project1.Blog">

<!-- TODO: Update blank fragment layout -->
<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#E0E0E0"
    android:id="@+id/blog_list"
    android:layout_marginTop="55dp">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="45dp"
            android:layout_height="43dp"
            android:adjustViewBounds="true"
            android:id="@+id/post_userpic"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:scaleType="centerCrop"
            android:src="@drawable/user_pic"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/post_username"
                    android:text="username"
                    android:textColor="#000000"
                    android:paddingTop="14dp"
                    android:paddingLeft="10dp"
                    android:textSize="14dp"
                    android:textStyle="normal|bold"
                    android:fontFamily="sans-serif"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="posted this"
                    android:layout_marginLeft="4dp"
                    android:textSize="14dp"
                    android:textStyle="normal"
                    android:fontFamily="sans-serif"/>
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="time"
                    android:id="@+id/post_time"
                    android:textColor="#BDBDBD"
                    android:layout_marginLeft="11dp"
                    android:layout_marginTop="3dp"
                    android:textSize="12dp"
                    android:textStyle="normal"
                    android:fontFamily="sans-serif"/>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/post_title"
        android:text="Post Title Goes Here"
        android:padding="10dp"
        android:textSize="16dp"
        android:textStyle="normal|bold"
        android:fontFamily="sans-serif"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/post_image"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"
        android:src="@mipmap/add_btn" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/post_desc"
        android:padding="10dp"
        android:textColor="#000000"
        android:paddingBottom="15dp"
        android:textSize="16dp"
        android:text="The Post Description Goes Here"/>
</LinearLayout>

1.(a)fragment_blog.xml的recyclerview中的Carview

<FrameLayout 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"
tools:context="com.example.aadarshkumarsingh.project1.Blog">

<!-- TODO: Update blank fragment layout -->
<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#E0E0E0"
    android:id="@+id/blog_list"
    android:layout_marginTop="55dp">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="45dp"
            android:layout_height="43dp"
            android:adjustViewBounds="true"
            android:id="@+id/post_userpic"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:scaleType="centerCrop"
            android:src="@drawable/user_pic"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/post_username"
                    android:text="username"
                    android:textColor="#000000"
                    android:paddingTop="14dp"
                    android:paddingLeft="10dp"
                    android:textSize="14dp"
                    android:textStyle="normal|bold"
                    android:fontFamily="sans-serif"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="posted this"
                    android:layout_marginLeft="4dp"
                    android:textSize="14dp"
                    android:textStyle="normal"
                    android:fontFamily="sans-serif"/>
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="time"
                    android:id="@+id/post_time"
                    android:textColor="#BDBDBD"
                    android:layout_marginLeft="11dp"
                    android:layout_marginTop="3dp"
                    android:textSize="12dp"
                    android:textStyle="normal"
                    android:fontFamily="sans-serif"/>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/post_title"
        android:text="Post Title Goes Here"
        android:padding="10dp"
        android:textSize="16dp"
        android:textStyle="normal|bold"
        android:fontFamily="sans-serif"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/post_image"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"
        android:src="@mipmap/add_btn" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/post_desc"
        android:padding="10dp"
        android:textColor="#000000"
        android:paddingBottom="15dp"
        android:textSize="16dp"
        android:text="The Post Description Goes Here"/>
</LinearLayout>
blogrow.xml

<FrameLayout 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"
tools:context="com.example.aadarshkumarsingh.project1.Blog">

<!-- TODO: Update blank fragment layout -->
<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#E0E0E0"
    android:id="@+id/blog_list"
    android:layout_marginTop="55dp">
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="45dp"
            android:layout_height="43dp"
            android:adjustViewBounds="true"
            android:id="@+id/post_userpic"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:scaleType="centerCrop"
            android:src="@drawable/user_pic"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/post_username"
                    android:text="username"
                    android:textColor="#000000"
                    android:paddingTop="14dp"
                    android:paddingLeft="10dp"
                    android:textSize="14dp"
                    android:textStyle="normal|bold"
                    android:fontFamily="sans-serif"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="posted this"
                    android:layout_marginLeft="4dp"
                    android:textSize="14dp"
                    android:textStyle="normal"
                    android:fontFamily="sans-serif"/>
            </LinearLayout>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="time"
                    android:id="@+id/post_time"
                    android:textColor="#BDBDBD"
                    android:layout_marginLeft="11dp"
                    android:layout_marginTop="3dp"
                    android:textSize="12dp"
                    android:textStyle="normal"
                    android:fontFamily="sans-serif"/>
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/post_title"
        android:text="Post Title Goes Here"
        android:padding="10dp"
        android:textSize="16dp"
        android:textStyle="normal|bold"
        android:fontFamily="sans-serif"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/post_image"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"
        android:src="@mipmap/add_btn" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/post_desc"
        android:padding="10dp"
        android:textColor="#000000"
        android:paddingBottom="15dp"
        android:textSize="16dp"
        android:text="The Post Description Goes Here"/>
</LinearLayout>

我正在使用毕加索广场图书馆获取图像,它工作正常。希望能解决,因为我一直在寻找解决方案,但实际问题的解决方案不可用。 先谢谢你

显示来自数据库的数据的Java类:

2.Blog.java

@Override
public void onStart() {
    super.onStart();

    FirebaseRecyclerAdapter<NewsBlog, BlogViewHolder> firebaseRecyclerAdapter =
            new FirebaseRecyclerAdapter<NewsBlog, BlogViewHolder>(
                    NewsBlog.class,
                    R.layout.blog_row,
                    BlogViewHolder.class,
                    mChildRef) {
                @Override
                protected void populateViewHolder(BlogViewHolder viewHolder, NewsBlog model, int position) {

                    viewHolder.setTitle(model.getTitle());
                    viewHolder.setImage(getContext(),model.getImage());
                    viewHolder.setDesc(model.getDesc());
                    viewHolder.setUsername(model.getUsername());
                    viewHolder.setPost_time(model.getPost_time());
                    viewHolder.setUserpic(getContext(),model.getUserpic());
                }
            };

    mBlogList.setAdapter(firebaseRecyclerAdapter);
}

public static class BlogViewHolder extends RecyclerView.ViewHolder{

    View mView;

    public BlogViewHolder(View itemView) {
        super(itemView);

        mView = itemView;
    }

    public void setTitle(String title){
        TextView post_title = (TextView) mView.findViewById(R.id.post_title);
        post_title.setText(title);
    }

    public void setImage(Context ctx, String image){
        ImageView post_image = (ImageView) mView.findViewById(R.id.post_image);
        Picasso.with(ctx).load(image).into(post_image);
    }

    public void setDesc(String desc){
        TextView post_desc = (TextView) mView.findViewById(R.id.post_desc);
        post_desc.setText(desc);
    }

    public void setUsername(String username){
        TextView mUsername = (TextView) mView.findViewById(R.id.post_username);
        mUsername.setText(username);
    }

    public void setPost_time(Long post_time) {
        TextView time = (TextView) mView.findViewById(R.id.post_time);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM d, ''yy 'at' HH:mma");
        time.setText(simpleDateFormat.format(new Date(post_time)));
    }

    public void setUserpic(Context ctx, String userpic){
        ImageView userImage = (ImageView) mView.findViewById(R.id.post_userpic);
        Picasso.with(ctx).load(userpic).into(userImage);
    }
}
@覆盖
public void onStart(){
super.onStart();
FirebaseRecyclerAdapter FirebaseRecyclerAdapter=
新型FirebaseRecyclerAdapter(
NewsBlog.class,
R.layout.blog_行,
BlogViewHolder.class,
麦克希尔德雷夫){
@凌驾
受保护的void populateViewHolder(BlogViewHolder、NewsBlog模型、int位置){
setTitle(model.getTitle());
setImage(getContext(),model.getImage());
setDesc(model.getDesc());
viewHolder.setUsername(model.getUsername());
viewHolder.setPost_time(model.getPost_time());
setUserpic(getContext(),model.getUserpic());
}
};
mBlogList.setAdapter(firebaseRecyclerAdapter);
}
公共静态类BlogViewHolder扩展了RecyclerView.ViewHolder{
视图视图;
公共BlogViewHolder(查看项目视图){
超级(项目视图);
mView=项目视图;
}
公共无效集合标题(字符串标题){
TextView post_title=(TextView)mView.findViewById(R.id.post_title);
post_title.setText(title);
}
公共void setImage(上下文ctx,字符串图像){
ImageView post_image=(ImageView)mView.findviewbyd(R.id.post_image);
毕加索.with(ctx).load(image).into(post_image);
}
公共void setDesc(字符串desc){
TextView post_desc=(TextView)mView.findViewById(R.id.post_desc);
后描述设置文本(描述);
}
public void setUsername(字符串用户名){
TextView mUsername=(TextView)mView.findViewById(R.id.post_用户名);
mUsername.setText(用户名);
}
公共无效设置post_时间(长post_时间){
TextView时间=(TextView)mView.findviewbyd(R.id.post_时间);
SimpleDataFormat SimpleDataFormat=新的SimpleDataFormat(“MMM d,'yy'位于'HH:mma”);
setText(SimpleDataFormat.format(新日期(发布时间));
}
public void setUserpic(上下文ctx,字符串userpic){
ImageView userImage=(ImageView)mView.findviewbyd(R.id.post_userpic);
毕加索.with(ctx).load(userpic).into(userImage);
}
}

上面是将图像设置为cardview的支架。

在毕加索中使用占位符非常感谢Shubham,它很有效。