2012-08-05 57 views
0

如何防止ScrollView在LinearLayout内容下滚动内容? ScrollView只是使用所有的显示空间,我不能限制它。 尝试使用主要的Relative-和LinearLayout。ScrollView在其他内容下滚动

我的代码:

<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> 

回答

1

这似乎有点奇怪,我认为你有你的滚动视图内的RelativeLayout ..但如果我正确理解你的问题,你要滚动视图是,你有没有上的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> 
+0

嘿,我已经给小图像留下底部,滚动视图默认线性布局有大数据,所以这个线性数据与图像重叠,对于更大的屏幕,这不是问题。对于小屏幕这是一个问题(4“屏幕是问题) – Prasad 2014-11-26 07:24:10

1

您还没有发布您的整个XML代码;我只能猜测这些元素都包含在LinearLayoutvertical方向中。

要获得ScrollView以填充LinearLayout未采用的所有空间,请使用layout_weight

<ScrollView 
    android:id="@+id/ScrollView1" 
    android:layout_width="match_parent" 
    android:layout_height="0px" 
    android:layout_weight="1" > 
+0

其含有的RelativeLayout – 2012-08-05 21:15:23

+0

阿内,那么,在这种情况下,你可能想切换布局类型,因为你不希望两者重叠。有什么让你使用'RelativeLayout'? – Eric 2012-08-05 21:53:40

+0

我现在改为线性布局,但是我收到了错误消息“LinearLayout:layout_centerHorizo​​ntal中的无效lyout参数”,与layout_below相同 – 2012-08-05 22:36:10