我正在制作一个简单的应用,我在其中使用Firebase在firebase存储上传图片。上传工作正常。当我尝试使用地图片段在应用的其他部分下载上传的图片时,图片无法显示。但是,如果我尝试在没有地图的活动中下载并显示图像,则图像显示正常。
我用于检索图片的代码
try {
final File tmpFile = File.createTempFile("img", "png");
sreference = FirebaseStorage.getInstance().getReference("photos");
sreference.child("my").getFile(tmpFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Bitmap pic = BitmapFactory.decodeFile(tmpFile.getAbsolutePath());
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
pic = Bitmap.createScaledBitmap(pic, fixerpic.getWidth(),fixerpic.getHeight(),true);
}
fixerpic.setImageBitmap(pic);
}
});
} catch (Exception e) {
e.printStackTrace();
}
图片无法显示的活动的xml布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.15"
android:layout_margin="0dp">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="digiart.mapwithfirebase.MapsActivity" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@color/white"
android:layout_weight="0.85">
<ImageView << This imageview
android:layout_width="100dp"
android:layout_height="match_parent"
android:id="@id/fixerimage"/>
<TextView
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:text="NAME"
android:textAlignment="center"
android:gravity="center"
android:textSize="16dp"
android:textColor="@color/colorAccent"
android:id="@+id/fixer_name"/>
<Button
android:id="@+id/button1"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/call"
android:layout_marginRight="8dp"
android:onClick="makecall"/>
<Button
android:id="@+id/button2"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/message"
android:layout_marginRight="8dp"
android:onClick="sendmessage"/>
<Button
android:id="@+id/favbtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/favourite"
android:layout_marginRight="8dp"
android:onClick="favourite"/>
</LinearLayout>
</LinearLayout>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="@+id/map_progbar"
android:visibility="gone"/>
</RelativeLayout>
图像正常显示的活动中的xml布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:gravity="center"
android:background="@drawable/bggradient2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<Button
android:layout_width="200dp"
android:layout_height="60dp"
android:text="Select Image"
android:onClick="selectimage"/>
<ImageView << This imageview
android:layout_width="200dp"
android:layout_height="200dp"
android:id="@+id/image"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kindly Fill Your Correct Details"
android:textAlignment="center"
android:textSize="18dp"
android:textColor="@color/white"
android:layout_gravity="center"
android:layout_marginBottom="40dp"/>
<EditText
android:id="@+id/reg_fixer_name"
android:layout_width="280dp"
android:layout_height="50dp"
android:hint="Full Name"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:layout_marginBottom="10dp"
android:textAlignment="center"
android:layout_gravity="center"/>
<EditText
android:id="@+id/register_fixer_phone"
android:layout_width="280dp"
android:layout_height="50dp"
android:hint="Phone Number"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:layout_marginBottom="10dp"
android:textAlignment="center"
android:layout_gravity="center"
android:inputType="number"/>
<TextView
android:layout_width="280dp"
android:layout_height="50dp"
android:text="Your Location: _________"
android:textAlignment="center"
android:gravity="center"
android:textColor="@color/white"
android:layout_marginBottom="10dp"
android:id="@+id/locationshowtxt"/>
<Button
android:layout_width="280dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="@drawable/round_corner_white"
android:text="Get My Location First"
android:layout_marginBottom="10dp"
android:textColor="@color/orange"
android:onClick="getlocation"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Your Expertise From Dopdown below"
android:textAlignment="center"
android:layout_gravity="center"
android:textColor="@color/white"
android:layout_marginBottom="10dp"/>
<Spinner
android:layout_width="280dp"
android:layout_height="50dp"
android:padding="5dp"
android:layout_gravity="center"
android:background="@drawable/round_corner_white"
android:id="@+id/dropdown">
</Spinner>
<Button
android:id="@+id/register_userbtn"
android:layout_width="280dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:background="@drawable/round_corner_white"
android:text="Register"
android:layout_marginTop="10dp"
android:textColor="@color/colorPrimaryDark"
android:onClick="register_fixer_btn"/>
</LinearLayout>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:id="@+id/reg_fixer_progbar"
android:visibility="gone"/>
</RelativeLayout>