图像自动被裁剪而从火力地堡检索存储
问题描述:
我在火力地堡存储上传的图片,并在图片看起来很好,当我看到他们在火力点的寄存,但是当我在我的活动检索这些图像的图像会从上攻裁剪和不利的是,这发生在高度较长的图片上。我在火力地堡发送图像像图像自动被裁剪而从火力地堡检索存储
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));
}
});
}
这是PostActicity 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" />
这就是我如何获取图片:
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: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" />
答
根据你的需要,你必须正确地使用android:scaleType
属性。您可以在地方centerCrop
使用fitcenter
。
<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
谢谢它的工作......! –
你能后的'mImage' ImageView的配置?无论是XML或Java很好 – bash
检查编辑版本@bash –
这不是一个Android Studio问题,所以不要使用Android Studio标记 – Zoe