android 关于视图缩放,android - Android Photoview通过缩放移动相对视图 - 堆栈内存溢出...

作者描述了一个使用ViewPager展示图像并希望同步调整图片大小和下方文本视图的问题。他们尝试通过自定义ImageAdapter实现,但遇到图像缩放与文本视图布局不随图像调整的问题。寻求解决方案以实现流畅的滚动和响应式布局。
摘要由CSDN通过智能技术生成

我的ViewPager具有以下布局,基本上可以循环浏览各种图像。

android:layout_width="fill_parent"

android:layout_height="wrap_content">

android:id="@+id/imagePager_container"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:id="@+id/imagePager_imageView"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

android:id="@+id/imagePager_textTitle"

android:layout_width="fill_parent"

android:gravity="center"

android:textStyle="bold"

android:text="TITLE"

android:layout_margin="0dp"

android:layout_below="@+id/imagePager_imageView"

android:layout_height="wrap_content"/>

android:layout_width="fill_parent"

android:layout_below="@+id/imagePager_textTitle"

android:layout_height="match_parent"

android:paddingLeft="5dp"

android:paddingRight="5dp"

android:src="@drawable/linebig"/>

android:id="@+id/imagePager_textSubtitle"

android:layout_width="fill_parent"

android:gravity="center"

android:text="SUBTITLE"

android:layout_margin="0dp"

android:layout_below="@+id/imagePager_titleLine"

android:layout_height="wrap_content"/>

android:layout_below="@+id/imagePager_textSubtitle"

android:layout_width="fill_parent"

android:layout_height="match_parent"

android:paddingLeft="30dp"

android:paddingRight="30dp"

android:paddingBottom="10dp"

android:src="@drawable/linebig"/>

android:id="@+id/imagePager_textContent"

android:layout_width="fill_parent"

android:paddingTop="15dp"

android:paddingLeft="20dp"

android:paddingRight="20dp"

android:text="CONTENT"

android:layout_margin="0dp"

android:layout_below="@+id/imagePager_subtitleLine"

android:layout_height="wrap_content"/>

从下面您可以看到的图像中,我也看到了一些描述性的视图。 我要实现的目标如下。

当图像出现时,我希望它缩小到屏幕宽度

显然,某些图像会比屏幕高度更长,并且会将说明下推,所以我希望能够滚动。 这就是为什么我使用scrollview。

最重要的是,我想放大和缩小图像,并且当我这样做时,我希望描述相应地移动。

我的ImageAdapter如下(仅包括相关方法):

@Override

public Object instantiateItem(ViewGroup container, int position) {

View layout = null;

if (container.getContext() != null) {

//load imagepager layout

LayoutInflater inflater = (LayoutInflater) container.getContext()

.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

layout = inflater.inflate(R.layout.image_pager, container, false);

if (layout != null) {

//Fill in textviews

//get current bitmap depending on viewpager position

//Bitmap is saved as byte[] in container

int imageNumber = getImageNumber(position);

BitmapContainer bitmap = getBitmap(imageNumber);

//create imageview

setImageview(layout, bitmap);

container.addView(layout, ActionBar.LayoutParams.FILL_PARENT,

ActionBar.LayoutParams.FILL_PARENT);

}

}

return layout;

}

private void setImageview(View layout, BitmapContainer container) {

PhotoView iv = (PhotoView) layout.findViewById(R.id.imagePager_imageView);

iv.setScaleType(ImageView.ScaleType.CENTER_CROP);

Bitmap bitmap = BitmapFactory.decodeByteArray(container.getImage(), 0,

container.getImage().length);

iv.setImageBitmap(bitmap);

}

}

问题在于,位图不会同时调整其imageview的大小,并且下面的textview仍然保持不变。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你在使用 Android Studio 中进行开发,可以尝试在 `build.gradle` 文件中添加以下依赖项: ``` dependencies { implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:cardview-v7:28.0.0' implementation 'com.android.support:palette-v7:28.0.0' implementation 'com.android.support:support-vector-drawable:28.0.0' implementation 'com.android.support:animated-vector-drawable:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support:support-annotations:28.0.0' implementation 'com.android.support:support-compat:28.0.0' implementation 'com.android.support:support-core-ui:28.0.0' implementation 'com.android.support:support-core-utils:28.0.0' implementation 'com.android.support:support-fragment:28.0.0' implementation 'com.android.support:multidex:1.0.3' implementation 'com.google.android.gms:play-services-ads:17.2.1' implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.jakewharton:butterknife:10.1.0' annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0' implementation 'com.github.bumptech.glide:glide:4.8.0' annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0' implementation 'com.squareup.retrofit2:retrofit:2.5.0' implementation 'com.squareup.retrofit2:converter-gson:2.5.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1' implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.afollestad.material-dialogs:core:0.9.6.0' implementation 'com.github.siyamed:android-shape-imageview:0.9.+@aar' implementation 'com.squareup.okhttp3:okhttp:3.12.0' implementation 'com.github.chrisbanes:PhotoView:2.1.3' implementation 'com.google.android:flexbox:1.0.0' implementation 'com.android.support:mediarouter-v7:28.0.0' implementation 'com.android.support:preference-v7:28.0.0' implementation 'com.android.support:exifinterface:28.0.0' implementation 'com.google.android.gms:play-services-maps:16.0.0' implementation 'com.google.android.gms:play-services-auth:16.0.1' implementation 'com.google.android.gms:play-services-location:16.0.0' implementation 'com.google.android.gms:play-services-places:16.0.0' implementation 'com.google.android.gms:play-services-gcm:16.0.0' implementation 'com.google.android.gms:play-services-analytics:16.0.7' implementation 'com.google.android.gms:play-services-ads-identifier:16.0.0' implementation 'com.google.firebase:firebase-core:16.0.8' implementation 'com.google.firebase:firebase-ads:17.2.1' implementation 'com.firebaseui:firebase-ui-auth:4.1.0' implementation 'com.firebaseui:firebase-ui-database:4.1.0' implementation 'com.firebaseui:firebase-ui-storage:4.1.0' implementation 'com.firebaseui:firebase-ui-firestore:4.1.0' implementation 'com.firebaseui:firebase-ui:4.1.0' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9' implementation 'com.google.android.gms:play-services-vision:17.0.2' } ``` 然后,再检查你的 AndroidManifest.xml 文件是否已经声明了相机权限: ``` <uses-feature android:name="android.hardware.camera" android:required="true" /> <uses-feature android:name="android.hardware.camera.autofocus" /> <uses-permission android:name="android.permission.CAMERA" /> ``` 如果还是找不到 `android.hardware:camera:2.0`,可以尝试在 SDK Manager 中更新你的 Android SDK。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值