您的位置:首页 > 移动开发 > Android开发

Android ScrollView 中放入 ImageView 导致的出现上下白边的问题?

2017-04-19 17:38 525 查看
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  

    android:layout_width="match_parent"  

    android:layout_height="match_parent"  

    android:orientation="vertical" >  

    <include  

        android:id="@+id/***"  

        layout="@layout/***" />  

    <ScrollView  

        android:layout_width="match_parent"  

        android:layout_height="match_parent">  

            <ImageView  

                android:id="@+id/iv_guide_detail"  

                android:layout_width="wrap_content"  

                android:layout_height="wrap_content"  

                android:layout_gravity="center_horizontal" />  

    </ScrollView>  

</LinearLayout>  

这样在手机上面会出现ImageView上下都有一块空白,解决问题的做法就是在ImageView 中添加下面的一段代码:

[html] view
plain copy

 





scaleType=“fillXY”  

这样也有弊端,图片会出现轻微缩放,导致失真。

或者


让ImageView全部适应ScrollView

博客分类: 

androidAndroid 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 

    android:layout_width="fill_parent" android:layout_height="fill_parent" 

    android:fillViewport="true"> 

    <LinearLayout android:orientation="vertical" 

        android:layout_width="fill_parent" android:layout_height="fill_parent"> 

        <ImageView android:layout_width="fill_parent" 

            android:layout_height="wrap_content" android:src="@drawable/huge" 

            android:scaleType="fitCenter" android:layout_weight="1" /> 

        <LinearLayout android:layout_width="wrap_content" 

            android:layout_height="wrap_content"> 

            <!-- Insert your content here --> 

        </LinearLayout> 

    </LinearLayout> 
</ScrollView> 

 

android:fillViewport="true"  必须设置的啊
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐