1

你好,我有一个ImageView(背景)的高度应该对应屏幕高度,另一方面宽度应该保持不变。图像视图占据整个背景,用户可以向右或向左滚动看到整个图像 -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"> 
... 

这工作得很好做。我的目标是动画滚动,做我需要摆脱水平视图(以防止用户滚动),但每当我更改Horizo​​ntalScrollView框架/相对布局(宽度设置为wrap_content)图像视图会缩小以适应屏幕。

有没有办法让ImageView的宽度不变(与高度匹配屏幕),这样它会比手机屏幕保持更大?(不裁剪)

然后我可以使用自定义动画滚动对。

我看过类似的问题,但我无法找到任何可以在这种情况下工作的东西。

回答

2

你可以做的是尝试覆盖Horizo​​ntalScrollView的onTouchListener。

例如,这样的事情:

scrollView.setOnTouchListener(new OnTouch()); 

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

这从滚动Horizo​​ntalScrollView,而你很可能还是把它的滚动编程方式禁用用户。

+0

我想过,但没有一种方法可以做到这一点,而不使用Horizo​​ntalScrollView? –

+0

我不确定。你说当你删除Horizo​​ntalScrollView时,图像被缩小了。你可以尝试玩ImageView的ScaleType。如果其中一个可用的ScaleType工作,则可以尝试通过在ImageView上使用translationX动画来执行“滚动”。 – JaapM

+0

Aww尝试了ScaleType和AdjustViewBounds的每种组合,并且每一个组合似乎都试图适应设备屏幕。它的做法是在xxhdpi可绘制文件夹中有相同图像的几个版本,当我更改scaleType时,只需选择适合屏幕并显示它的较小图像。 –