我正在开发一个安卓项目。在这个项目中,我需要处理ScrollView
来滚动图片。但是当我在ScrollView
里使用ImageView
时,给我的图片不适合UI布局。所以我想把ScrollView
转换成ImageView
。在安卓中有没有这样的方法呢?请帮帮我。
我正在开发一个安卓项目。在这个项目中,我需要处理ScrollView
来滚动图片。但是当我在ScrollView
里使用ImageView
时,给我的图片不适合UI布局。所以我想把ScrollView
转换成ImageView
。在安卓中有没有这样的方法呢?请帮帮我。
我找到了一个好的解决方案,在你的ImageView参数中,只需添加-
android:adjustViewBounds="true"
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/describe_something_here"/>
</RelativeLayout>
</ScrollView>
如果您想将ImageView适配到模拟器屏幕中,为什么要使用ScrollView呢?您可以像这样在模拟器屏幕中缩放您的ImageView。
LinearLayout linLayout = new LinearLayout(this);
// load the origial BitMap (500 x 500 px)
Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
R.drawable.android);
int width = bitmapOrg.width();
int height = bitmapOrg.height();
int newWidth = 200;
int newHeight = 200;
// calculate the scale - in this case = 0.4f
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// createa matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// rotate the Bitmap
matrix.postRotate(45);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
width, height, matrix, true);
// make a Drawable from Bitmap to allow to set the BitMap
// to the ImageView, ImageButton or what ever
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
ImageView imageView = new ImageView(this);
// set the Drawable on the ImageView
imageView.setImageDrawable(bmd);
// center the Image
imageView.setScaleType(ScaleType.CENTER);
// add ImageView to the Layout
linLayout.addView(imageView,
new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT
)
);
// set LinearLayout as ContentView
setContentView(linLayout);
希望能有所帮助
你好,我认为你可以这样解决你的问题
<anyLayout>
<ScrollView>
<RelativeLayout>
<ImageView/>
</RelativeLayout>
</ScrollView>
</anyLayout>
滚动视图在布局内工作。
<ScrollView>
<RelativeLayout>
<ImageView/>
</RelativeLayout>
</ScrollView>
这将对你有用
我找到了一个非常简单的解决方案,你只需要添加
android:src="@drawable/hayhouse"
在布局的xml文件中,将其返回到您的ImageView。