我有一台带RelativeLayout
和ImageView
的HorizontalScrollView
。我的目标是让ImageView以全高但溢出宽度显示我的图像,以便您可以水平滚动图像。
下面是我的xml:
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_indoor_tour"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ff0000">
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scene"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="#ffff00" />
</RelativeLayout>
</HorizontalScrollView>
它通常可以工作,但添加了一些左右间距,这是ImageView的一部分。
请参见屏幕截图。
间隔是从哪里来的?如何删除这种间距?
发布于 2018-06-16 04:58:22
下面的代码在我的例子中工作得很好。
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_indoor_tour"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000">
<ImageView
android:id="@+id/scene"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="#ffff00" />
</RelativeLayout>
</HorizontalScrollView>
我认为图像本身有一个左右填充。除此之外,它应该工作得很好。
发布于 2018-06-16 04:42:12
尝试在imageView上添加此属性:
android:scaleType="fitXY"
或
android:layout_width="match_parent"
相对于相对布局和ImageView
https://stackoverflow.com/questions/50882318
复制相似问题