我使用通用图像加载器将一些imageview(大高度)加载到listview 这是活动中的listview(自定义放大/缩小):
<noname.test1.CustomListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/listviewImg" />
这是listview的list_img.xml:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageview1">
</ImageView>
这是我要加载的图片(尺寸400px X 5312px):
link
当节目全屏或更大时,我想要图像
如何解决?
答案 0 :(得分:0)
你应该改变imageViwe的scaleType并将adjustViewBound设置为true:
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageview1"
android:scaleType="centerCrop"
android:adjustViewBounds="true">
</ImageView>
您可以尝试使用scaleType的其他选项,看看哪一个适合您!
你可以在这里阅读scaleType: scaleTypes
答案 1 :(得分:0)
创建此类并使用它而不是imageView
/**
* Created by farazkhonsari on 1/26/16.
*/
public class ScaledImageView extends ImageView {
public ScaledImageView(Context context) {
super(context);
}
public ScaledImageView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ScaledImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
try {
Drawable drawable = getDrawable();
if (drawable == null) {
setMeasuredDimension(0, 0);
} else {
int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
int measuredHeight = MeasureSpec.getSize(heightMeasureSpec);
int width = measuredWidth;
int height = width * drawable.getIntrinsicHeight() / drawable.getIntrinsicWidth();
setMeasuredDimension(width, height);
}
} catch (Exception e) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
并在布局中使用此类:
<ir.farazGroup.YeJoke.tools.ScaledImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/c"
android:scaleType="fitCenter"
/>
答案 2 :(得分:0)
尝试此解决方案:[在给列表充气后将其设置在onCreate或onCreateView中]
imageView = (ImageView) findViewById(R.id. imageview1);
Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
float screenWidth = metrics.widthPixels;
imageView.getLayoutParams().width = (int) screenWidth; // Takes the whole screen width
答案 3 :(得分:0)
尝试这个我希望我会帮助你
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:src="@drawable/locked_image"
android:scaleType="fitXY"
/>