如何防止 ScrollView 滚动 LinearLayout 内容下的内容? ScrollView 仅使用所有显示空间,我无法限制这一点。 尝试使用主要的Relative- 和LinearLayout。
我的代码:
<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
xmlns:myapp="http://schemas.android.com/apk/res/your.app.package"
android:id="@+id/ad_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
<ScrollView
android:id="@+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1" >
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:contentDescription="@string/image"
android:onClick="openImage1"
android:scaleType="fitStart"
android:src="@drawable/loading"
android:adjustViewBounds="true"
android:background="#000000" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
最佳答案
对我来说,你的 ScrollView 中有一个relativelayout,这似乎有点奇怪。但是如果我正确理解你的问题,你希望 ScrollView 位于你在那里的上部 LinearLayout 的下面。我猜您正在寻找类似以下内容的内容:(看看我添加的新 LinearLayout
和 android:layout_below
。我还更改了外部布局到 RelativeLayout
;同样,我不确定您到底想要做什么,但我希望这在某种程度上有所帮助。)
<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:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
xmlns:myapp="http://schemas.android.com/apk/res/your.app.package"
android:id="@+id/ad_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
</LinearLayout>
<LinearLayout
android:id="@+id/below_ad_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@+id/ad_layout" >
<ScrollView
android:id="@+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1" >
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:contentDescription="@string/image"
android:onClick="openImage1"
android:scaleType="fitStart"
android:src="@drawable/loading"
android:adjustViewBounds="true"
android:background="#000000" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
</RelativeLayout>
关于java - ScrollView 在其他内容下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11819895/