【发布时间】:2015-12-05 23:44:48
【问题描述】:
我在将 android.support.percent.PercentRelativeLayout 与 ScrollView 结合时遇到问题。以下xml文件
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="none">
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:background="@color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<ImageView
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="5%"
app:layout_marginLeftPercent="5%"
android:src="@drawable/o"
android:id="@+id/imageView3" />
<ImageView
android:layout_height="match_parent"
android:layout_width="match_parent"
app:layout_widthPercent="50%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="30%"
app:layout_marginLeftPercent="5%"
android:src="@drawable/o"
android:layout_below="@+id/imageView3"
android:layout_alignStart="@+id/imageView3"
android:layout_marginTop="151dp" />
</android.support.percent.PercentRelativeLayout>
使用RelativeLayout 可以正常工作。 有谁知道问题出在哪里?谢谢!
编辑:如果我将 ScrollView 高度设置为 1000dp,它也可以正常工作,但我希望高度与元素一样多
【问题讨论】:
-
好的,它应该是什么样子的?而且,如果
RelativeLayout工作正常,为什么不使用它呢? -
我想使用百分比选项,但相对布局无法做到这一点,你知道我可以做到这一点吗?例如对于 RelativeLayout app:layout_widthPercent="50%" 不起作用。第二张图片的宽度和高度应与第一张相同,但要更低,但它仍保留在手机的第一个屏幕上,不会降低,因此用户可以通过滚动看到它。谢谢克里斯! :)
-
您是否希望第二张图片位于屏幕下方以便用户必须滚动才能看到它?跨度>
-
您能否简单介绍一下您的应用,以及在显示这些图像时发生了什么?
-
顺便说一句,如果您希望第二张图片位于屏幕下方,那么
RelativeLayout对您没有多大帮助。我有几个想法,但首先我需要确保我了解您要完成的工作。
标签: android android-scrollview android-relativelayout android-percentrelativelayout