2017-09-09 13 views
-1

Firebaseストレージに画像をアップロードしていますが、firebaseのStorageに表示されている画像が正常に表示されますが、アクティビティで画像を取得すると、これは、高さの長い写真で起こります。Firebase Storageから取得中に画像が自動的に切り取られます

mDatabase.child(mPostKey).addValueEventListener(new ValueEventListener() { 
     @Override 
     public void onDataChange(DataSnapshot dataSnapshot) { 

      String post_image=(String) dataSnapshot.child("Image").getValue(); 
      String post_uid=(String) dataSnapshot.child("uid").getValue(); 

      Picasso.with(profileSingleActivity.this).load(post_image).into(mImage); 


     } 

     @Override 
     public void onCancelled(DatabaseError databaseError) { 

     } 
    }); 

これは、活動のXMLファイルです。これは私が画像を検索しています方法です

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:foregroundGravity="center"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/back" 
     android:orientation="vertical"> 

     <ImageButton 
      android:id="@+id/MimageSelect" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:layout_gravity="center" 
      android:adjustViewBounds="true" 
      android:background="#00ffffff" 
      android:scaleType="centerCrop" 
      android:src="@mipmap/add_btn" /> 


    </LinearLayout> 
</ScrollView> 

<EditText 
    android:id="@+id/Mphone" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/submit" 
    android:layout_centerHorizontal="true" 
    android:layout_marginLeft="6dp" 
    android:layout_marginRight="6dp" 
    android:layout_marginBottom="5dp" 
    android:background="@drawable/input_outline" 
    android:ems="10" 
    android:hint="Caption" 
    android:padding="15dp" 
    android:singleLine="false" /> 
<Button 
    style="?android:attr/buttonStyleSmall" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="UPLOAD" 
    android:id="@+id/submit" 
    android:background="@color/colorPrimary" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:textColor="@android:color/white" 
    android:textStyle="bold" 
    android:textSize="16dp" /> 

:私は、これはPostActicity XMLファイルであること

ようFirebase上の画像
if(mImageUri!=null) // 
    { 
     StorageReference filepath=mstorage.child("Images").child(mImageUri.getLastPathSegment()); 
     filepath.putFile(mImageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { 
      @Override 
      public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 
       final Uri downloadUrl= taskSnapshot.getDownloadUrl(); 
       final DatabaseReference newPost=mDatabase.push(); 

       mDatabaseUser.addValueEventListener(new ValueEventListener() { 
        @Override 
        public void onDataChange(DataSnapshot dataSnapshot) { 

         newPost.child("Image").setValue(downloadUrl.toString()); 

         newPost.child("Name").setValue(dataSnapshot.child("name").getValue()).addOnCompleteListener(
           new OnCompleteListener<Void>() { 
          @Override 
          public void onComplete(@NonNull Task<Void> task) { 
           if(task.isSuccessful()) 
           { 
            startActivity(new Intent(PostActivity.this,MainActivity.class)); 
            finish(); 
           } 
           else 
           { 
            Toast.makeText(PostActivity.this,"An Error Has Occurred.",Toast.LENGTH_LONG).show(); 
           } 
          } 
         }); 
        } 

        @Override 
        public void onCancelled(DatabaseError databaseError) { 

         Toast.makeText(PostActivity.this,"Error Uploading data",Toast.LENGTH_LONG).show(); 
        } 
       }); 

       mProgress.dismiss(); 
       //startActivity(new Intent(PostActivity.this,setupActivity.class)); 
      } 
     }); 
    } 

を送信しています私が検索している画像:

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/scroll" 
    android:foregroundGravity="center"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/back" 
    android:orientation="vertical"> 
     <ImageButton 
      android:id="@+id/MimageSelect" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentTop="true" 
      android:layout_centerHorizontal="true" 
      android:layout_margin="12dp" 
      android:adjustViewBounds="true" 
      android:background="#00ffffff" 
      android:scaleType="centerCrop" 
      android:src="@mipmap/add_btn" /> 
</LinearLayout> 
</ScrollView> 

<Button 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Delete Post" 
    android:id="@+id/removeBtn" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:background="@color/design_textinput_error_color_light" 
    android:textColor="@color/abc_primary_text_disable_only_material_dark" 
    android:textStyle="bold" /> 
+0

'mImage' ImageView設定を投稿できますか? XMLまたはjavaのいずれかが問題ありません – bash

+0

編集バージョンをチェック@bash –

+0

これはAndroidスタジオの問題ではないので、Androidスタジオタグを使用しないでください。 – Zoe

答えて

1

必要に応じて、android:scaleType属性を正しく使用する必要があります。場所centerCropfitcenterを使用できます。

<ImageButton 
     android:id="@+id/MimageSelect" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_margin="12dp" 
     android:adjustViewBounds="true" 
     android:background="#00ffffff" 
     android:scaleType="centerCrop" 
     android:src="@mipmap/add_btn" />  

このURLを確認すると、画像で示されます。 https://robots.thoughtbot.com/android-imageview-scaletype-a-visual-guide

+0

それは働いてくれた... !! –

関連する問題