ImageView比屏幕大作为背景

时间:2017-06-07 14:01:44

标签: 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_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更改为Frame / Relative布局(宽度设置为wrap_content)时缩小图像视图以适合屏幕。

有没有办法保持imageView宽度不变(高度与屏幕高度相匹配),以便它仍然比设备屏幕更大?(没有裁剪)

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

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

1 个答案:

答案 0 :(得分: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,而您可能仍然可以通过编程方式滚动它。

相关问题