【问题标题】:How to display imageview in scrollview to all screen如何在滚动视图中将图像视图显示到所有屏幕
【发布时间】:2015-10-01 15:16:45
【问题描述】:

我正在尝试将图片显示到所有屏幕,当它不在 scrollView 中时一切正常,但是当我将 imageview 放到 scrollview 时,它们显示到屏幕的 60-80%。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/Background">



    <include layout="@layout/toolbar"
        android:id="@+id/toolbar" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView7"
        android:layout_below="@+id/toolbar"
        android:fillViewport="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/scrollView7">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/asana_image"
                    android:scaleType="centerCrop"
                    android:background="@color/Transparent"
                    android:src="@drawable/noimage"
                    android:layout_centerInParent="true"
                    android:adjustViewBounds="false" />

                <ImageButton
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:id="@+id/videoplay_but"
                    android:background="@drawable/blue_corn_bg"
                    android:src="@drawable/video"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_marginLeft="29dp"
                    android:layout_marginStart="29dp"
                    android:layout_marginTop="27dp"
                    android:scaleType="centerInside"
                    android:padding="18dp" />

                <ImageButton
                    android:layout_width="60dp"
                    android:layout_height="60dp"
                    android:id="@+id/sound_but"
                    android:src="@drawable/sound_image"
                    android:background="@drawable/blue_corn_bg"
                    android:layout_alignTop="@+id/videoplay_but"
                    android:layout_toRightOf="@+id/videoplay_but"
                    android:layout_toEndOf="@+id/videoplay_but"
                    android:layout_marginLeft="29dp"
                    android:layout_marginStart="29dp"
                    android:scaleType="centerInside"
                    android:padding="18dp" />
            </RelativeLayout>

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="New Text"
                    android:id="@+id/textView55"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true"
                    android:layout_marginTop="17dp" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="New Text"
                    android:id="@+id/textView56" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="New Text"
                    android:id="@+id/textView57"
                    android:layout_below="@+id/textView55"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true" />

            </RelativeLayout>

        </RelativeLayout>
    </ScrollView>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar"
        android:id="@+id/VideoLay"
        android:visibility="invisible">

        <VideoView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/videoAsana"
            android:visibility="visible"
            android:layout_centerHorizontal="true"
            android:layout_alignParentTop="true" />
    </RelativeLayout>



</RelativeLayout>

在片段中:

if(imgFile.exists()){

            Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

            asana_image.setImageBitmap(myBitmap);


        }

我的错误在哪里? 谢谢!!!

截图:

【问题讨论】:

    标签: android xml imageview


    【解决方案1】:

    首先,您的相对布局位于滚动视图内,因此您不应将属性android:layout_below="@+id/scrollView7" 赋予您的相对布局。

    接下来是你应该给你的滚动视图match_parent而不是wrap_content

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
    
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/Background">
    
    
    
        <include layout="@layout/toolbar"
            android:id="@+id/toolbar" />
    
        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/scrollView7"
            android:layout_below="@+id/toolbar"
            android:fillViewport="true">
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/scrollView7">
    
                <RelativeLayout
                    android:id="@+id/relative1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
    
                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/asana_image"
                        android:scaleType="centerCrop"
                        android:background="@color/Transparent"
                        android:src="@drawable/noimage"
                        android:layout_centerInParent="true"
                        android:adjustViewBounds="false" />
    
                    <ImageButton
                        android:layout_width="60dp"
                        android:layout_height="60dp"
                        android:id="@+id/videoplay_but"
                        android:background="@drawable/blue_corn_bg"
                        android:src="@drawable/video"
                        android:layout_alignParentTop="true"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentStart="true"
                        android:layout_marginLeft="29dp"
                        android:layout_marginStart="29dp"
                        android:layout_marginTop="27dp"
                        android:scaleType="centerInside"
                        android:padding="18dp" />
    
                    <ImageButton
                        android:layout_width="60dp"
                        android:layout_height="60dp"
                        android:id="@+id/sound_but"
                        android:src="@drawable/sound_image"
                        android:background="@drawable/blue_corn_bg"
                        android:layout_alignTop="@+id/videoplay_but"
                        android:layout_toRightOf="@+id/videoplay_but"
                        android:layout_toEndOf="@+id/videoplay_but"
                        android:layout_marginLeft="29dp"
                        android:layout_marginStart="29dp"
                        android:scaleType="centerInside"
                        android:padding="18dp" />
                </RelativeLayout>
    
                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/relative1">
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="New Text"
                        android:id="@+id/textView55"
                        android:layout_alignParentTop="true"
                        android:layout_alignParentLeft="true"
                        android:layout_marginTop="17dp" />
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="New Text"
                        android:id="@+id/textView56" />
    
                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="New Text"
                        android:id="@+id/textView57"
                        android:layout_below="@+id/textView55"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentStart="true" />
    
                </RelativeLayout>
    
            </RelativeLayout>
        </ScrollView>
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/toolbar"
            android:id="@+id/VideoLay"
            android:visibility="invisible">
    
            <VideoView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/videoAsana"
                android:visibility="visible"
                android:layout_centerHorizontal="true"
                android:layout_alignParentTop="true" />
        </RelativeLayout>
    
    
    
    </RelativeLayout>
    

    【讨论】:

    • 将 android:layout_above="@+id/VideoLay" 添加到您的滚动视图中
    • 有了这个我只能看到 VideoLay。
    • 之前 asana_image.setImageBitmap(myBitmap);一切都很好,滚动后不起作用。(
    • 能否附上截图
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    • 1970-01-01
    相关资源
    最近更新 更多