如何在scrollview下放置新项目

时间:2011-11-30 14:15:58

标签: android layout limit scrollable

我有一个垂直可滚动的布局,有很多项目,工作正常 我试图在屏幕底部放置一个新的线性布局,它不会成为可滚动布局的一部分 也就是说,它会独立于可滚动部分位于按钮上(如广告视图)。 我只能将它放在scrollView中。
如何将其放置在下方,以便始终可见?

4 个答案:

答案 0 :(得分:20)

使用RelativeLayout,并按如下方式组织:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true"
        android:layout_alignParentTop="true"
        android:layout_above="@+id/linearLayoutThatDoesNotScroll" >

        <LinearLayout
            android:id="@+id/linearLayoutWithLotofContent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
        </LinearLayout>

    </ScrollView>

    <LinearLayout
        android:id="@+id/linearLayoutThatDoesNotScroll"  
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" >
    </LinearLayout>

</RelativeLayout>

诀窍在ScrollView放置中,同时它与屏幕顶部对齐并位于较低的固定LinearLayout上方。它只是有效。

答案 1 :(得分:5)

这样的事情:)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" >
    <ScrollView android:id="@+id/scroll_view"
        android:layout_width="fill_parent" 
        android:layout_height="0dp"
        android:layout_weight="1" >
        <LinearLayout android:id="@+id/content"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" />
    </ScrollView>
    <LinearLayout android:id="@+id/bottom"
        android:layout_width="fill_parent" 
        android:layout_height="10dip" />          
</LinearLayout>

您将使用android:id = bottom :)

将底部内容添加到底部linearLayout

答案 2 :(得分:1)

如果您使用垂直LinearLayout来保持可滚动布局,则可以将广告视图添加到可滚动布局下方的LinearLayout,它将显示在屏幕底部。 (假设您的权重设置正确,滚动布局设置为WRAP_CONTENT

RelativeLayout允许您设置广告视图以使其自身与可滚动布局的底部对齐,但您仍需要确保可滚动布局设置为WRAP_CONTENT,以便它没有自动占用整个屏幕。

答案 3 :(得分:1)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/dialogButtonOK"
        android:layout_width="100px"
        android:layout_height="wrap_content"
        android:text=" Ok "
        android:layout_alignParentBottom="true"
        android:layout_centerInParent="true"
        android:background="@drawable/button_style"
        />
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:id="@+id/scrView"
        android:layout_above="@id/dialogButtonOK"
        android:layout_alignParentTop="true"
       >
            <HorizontalScrollView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >
                      <TableLayout
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:stretchColumns="*"
                        android:id="@+id/main_table" >
                    </TableLayout>
            </HorizontalScrollView>
    </ScrollView>




</RelativeLayout>

这对我有用