【发布时间】:2013-09-30 14:21:38
【问题描述】:
我有一个 viewpager,我正在向其中添加一个 imageview; 我使用了 android:scaleType="fitXY" 但是图像周围仍然有一些黑色,为什么以及如何拉伸它使其就像背景一样? 谢谢。
viewpager 的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Introduction_Activity"
>
<android.support.v4.view.ViewPager
android:id="@+id/imgs_viewpager"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
图像视图布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:id="@+id/img_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/desc_intro"
android:scaleType="fitXY"
android:adjustViewBounds="true"
/>
</LinearLayout>
【问题讨论】:
-
你是用android:src设置背景吗?
-
我正在使用 img_v.setImageResource(position);因为它在viewpager中
-
android:src是设置imageview源,android:background会设置view的背景,你可以尝试把你的drawable设置为android:background而不是src,顺便说一句,你的imageview有layout_width吗和 layout_height = match_parent?
-
是的,我的布局宽度和高度与父级匹配,我尝试设置 imageview 的背景而不是 ressource 得到相同的结果将添加我的一些代码;