【发布时间】:2019-02-17 09:04:10
【问题描述】:
我有一系列缩略图。选择时,缩略图将替换 main_image。
我的布局是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/lightGray"
tools:context=".ExpandedProduct">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true">
<LinearLayout
android:id="@+id/product"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/main_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
</android.support.constraint.ConstraintLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/thumbnails"
android:layout_marginBottom="10sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
(每个缩略图都加载到回收器中。) 问题:当我点击缩略图时,它会成为主图像,但它非常小 - 比缩略图小。 (我试图将 main_image 包装在约束布局中 - 没有变化。)
为了对点击做出反应,我实现了一个设置适配器的界面。这是我的片段脚本中的 onClick 代码,其中缩略图成为主图像:
all_image.setAdapter(new ProductImagesAdapter(getProductImages(), new ProductImagesAdapter.OnItemSelectedListener()
{
@Override
public void onItemClick(String url)
{
ImageRequest manRequest = new ImageRequest(url, new Response.Listener<Bitmap>()
{
@Override
public void onResponse(Bitmap response)
{
main_image.setImageBitmap(response);
}
}, 0, 0, ImageView.ScaleType.CENTER_CROP, Bitmap.Config.RGB_565, new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error)
{
Log.d("Image Request", error.toString());
}
});
NetworkVolleySingleton.getInstance(getContext()).addToRequestQueue(manRequest);
}
}));
如您所见,我正在使用 Volley 从其 URL 加载图像。
如何让选定的缩略图图像填充 main_image“框架”?
【问题讨论】:
标签: android image scale thumbnails