Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 比屏幕大的图像视图作为背景_Android_Android Layout_Android Imageview_Horizontalscrollview - Fatal编程技术网

Android 比屏幕大的图像视图作为背景

Android 比屏幕大的图像视图作为背景,android,android-layout,android-imageview,horizontalscrollview,Android,Android Layout,Android Imageview,Horizontalscrollview,您好,我有一个ImageView(背景),它的高度应与屏幕高度相对应,另一方面,宽度应保持不变 在这样做之前 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="wrap_content" android:layout_height="match_par

您好,我有一个ImageView(背景),它的高度应与屏幕高度相对应,另一方面,宽度应保持不变

在这样做之前

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent">

 <HorizontalScrollView
     android:layout_width="wrap_content"
     android:layout_height="match_parent"> 

    <ImageView
        android:id="@+id/songDetails_songImage"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"
        android:contentDescription="@string/songDetails_cd_songCover"
        app:srcCompat="@drawable/default_song_cover" />

</HorizontalScrollView>  
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
...

...
这很好-图像视图占据整个背景,用户可以向右或向左滚动查看整个图像

我的目标是为滚动设置动画,为此我需要去掉水平视图(以防止用户滚动),但每当我将水平滚动视图更改为帧/相对布局(宽度设置为包裹内容)时,图像视图就会缩小以适应屏幕

有没有办法保持imageView的宽度不变(高度与屏幕一致),使其保持比设备屏幕大?(无裁剪)

然后我可以使用自定义动画向右滚动


我已经研究过类似的问题,但在这种情况下我找不到任何可行的方法。

您可以尝试覆盖HorizontalScrollView的onTouchListener

例如,类似这样的内容:

scrollView.setOnTouchListener(new OnTouch());

private class OnTouch implements OnTouchListener
{
    @Override
    public boolean onTouch(View v, MotionEvent event) {
    return true;
    }
}

这将禁用用户滚动HorizontalScrollView,而您可能仍然可以通过编程方式滚动它。

我考虑过这一点,但没有一种方法可以不用HorizontalScrollView进行滚动?我不确定。您的意思是,当您删除HorizontalScrollView时,图像会缩小。您可以尝试使用ImageView的ScaleType。如果其中一个可用的ScaleType有效,那么您可以尝试在ImageView上使用translationX动画进行“滚动”。Aww可能尝试了ScaleType和AdjustViewBounds的所有组合,并且每个组合似乎都在尝试适应设备屏幕。它的方式是,我在xxhdpi可绘制文件夹中有两个版本的相同图像,当我更改scaleType时,它只会选择适合屏幕的较小图像并显示它。