2012-08-05 74 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