Android毕加索将照片缩放到更大或适合imageView(无空白)
我有一个毕加索图书馆缩放严重的问题。问题是我有一个由3个主视图和一些按钮组成的布局。意见如下: ImageView 50% 地图视图20% EditTextView 30% 我想将分辨率未知的图片加载到imageView中,而不留下空白。我试图在内部使用.fit().centerInside,但这只会在侧面留下空白。我的布局是这样的:Android毕加索将照片缩放到更大或适合imageView(无空白),android,android-layout,picasso,android-bitmap,Android,Android Layout,Picasso,Android Bitmap,我有一个毕加索图书馆缩放严重的问题。问题是我有一个由3个主视图和一些按钮组成的布局。意见如下: ImageView 50% 地图视图20% EditTextView 30% 我想将分辨率未知的图片加载到imageView中,而不留下空白。我试图在内部使用.fit().centerInside,但这只会在侧面留下空白。我的布局是这样的: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" and
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="@+id/photo1"
android:weightSum="10">
<ImageView
android:id="@+id/photo1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:background="#75aea7ab" />
<com.google.android.gms.maps.MapView
android:id="@+id/map2"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2" />
<EditText
android:id="@+id/edittext"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:layout_weight="3"
android:background="#00000000"
android:gravity="top|left"
android:inputType="textMultiLine"
android:textColor="#ff000000"
android:textSize="15sp" />
</LinearLayout>
<ImageButton
android:id="@+id/post"
android:layout_width="@dimen/fab_button_diameter"
android:layout_height="@dimen/fab_button_diameter"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="end"
android:layout_marginBottom="300dp"
android:background="@drawable/fab_shape"
android:src="@drawable/forward"
android:text="Post!"
android:tint="@android:color/white" />
<Button
android:id="@+id/camera"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="75dp"
android:layout_marginTop="100dp"
android:background="@drawable/camera" />
<Button
android:id="@+id/gallery"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="75dp"
android:layout_marginTop="100dp"
android:background="@drawable/gallery" />
加载图像后,是否尝试设置缩放类型
mPicasso.load("yourUrl")
.into(yourImageView, new Callback() {
@Override
public void onSuccess() {
yourImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);//Or ScaleType.FIT_CENTER
}
@Override
public void onError() {
//nothing for now
}
});
因此,您有一个固定大小的
ImageView
,但大小不同的图像-您希望填充整个ImageView。在这种情况下,fit()。centerCrop()
似乎是一条出路。当然,它会裁剪您的图像,但是如果图像的纵横比不符合ImageView
的纵横比,您只有两个选择:(1)适合-带有白色条或(2)裁剪-图像的某些部分丢失。嘿,谢谢您的评论。我害怕这种反应。那么,有没有其他方法可以在不修剪的情况下实现这一点?我不确定我是否理解。。。是否要拉伸图像以适合ImageView?或者,是否要调整ImageView的大小以适应图像,即使这会破坏/更改整个布局。至于后者,请参见将我的评论包括在博客帖子中。前者可能通过转换
实现,但我必须亲自尝试和/或用谷歌搜索…嘿,这是个好主意,我的问题是我正在加载到目标中以从ImageView中提取位图,我将其放入目标中,效果非常好。感谢男士:)等等,这与fit().centerCrop()
或fit().centerInside()
有什么不同?首先,毕加索的fit()会缩小图像并使图像视图居中,但不会执行缩放,然后centerCrop会均匀地缩放图像(保持图像的纵横比),以便两个尺寸都保持一致图像的(宽度和高度)将等于或大于视图的相应尺寸(减去填充),但您仍然需要(在毕加索的情况下)为这个新位图提供宽度和高度,fit()。centerInside()也会这样做,但调用centerInside时,它应均匀缩放图像(保持图像的纵横比)。这是一个好问题,但是fit().centerCrop()或fit().centerInside()对我不起作用,但这是有效的。此外,我不能使用这些方法,因为我必须将其放入目标,而不是直接放入ImageView,因为我想获取位图的引用