java - ScrollView 在其他内容下滚动

标签 java android layout scrollview

如何防止 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 的下面。我猜您正在寻找类似以下内容的内容:(看看我添加的新 LinearLayoutandroid: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/

相关文章:

java - 控制反转与反射

java - 是否可以在增强的 for 循环中找到当前索引?

android - facebook android sdk 3.0 登录另一个 Activity 崩溃

android - InputKeyboard 上的 EditText 启动 在 android 中创建 IME

java.lang.NoClassDefFoundError(Java、Eclipse、Fuse-JNA、Ubuntu)

java - 签名的 Amazon s3 URL 可以安全共享吗?

android - openfire用户和roster用户的区别

java - 如何使我的 View 高度减半?

android - 更改运行时添加的 ProgressBar 的宽度

html - 两列向左浮动的 CSS