android ScrollView用户界面

android ScrollView用户界面,android,xml,Android,Xml,我在android中使用webview来显示文章,屏幕上还有“下一步”和“上一步”按钮来浏览文章。当内容较少时,上一个按钮必须显示在屏幕底部,当内容较大时,这些按钮必须显示在内容末尾 我如何实现这一点?目前我正在做如下工作: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:lay

我在android中使用webview来显示文章,屏幕上还有“下一步”和“上一步”按钮来浏览文章。当内容较少时,上一个按钮必须显示在屏幕底部,当内容较大时,这些按钮必须显示在内容末尾

我如何实现这一点?目前我正在做如下工作:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent">
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:padding="4dp">
                <TextView
                    android:id="@+id/article_title"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textSize="16dp"
                    android:text="ARTICLE NAME"
                    android:textColor="@color/colorPrimaryDark"
                    android:layout_weight="1"
                    android:gravity="center_vertical"
                    android:paddingLeft="4dp"
                    />
                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textSize="12dp"
                    android:text="Published date"
                    android:textColor="@color/colorSecondaryText_GRAY"
                    android:layout_weight="1"
                    android:id="@+id/article_publish_text"
                    android:paddingLeft="4dp"
                    />
                <TextView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:textSize="12dp"
                    android:text="FOLDER NAME"
                    android:textColor="@color/colorSecondaryText_GRAY"
                    android:layout_weight="1"
                    android:id="@+id/article_folder_name_text"
                    android:paddingLeft="4dp"
                    />

            </LinearLayout>

            <WebView
                android:id="@+id/pageInfo"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/border_set"></WebView>

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:layout_margin="4px"
                android:padding="4px"
                >
                <Button
                    android:id="@+id/button_prev"
                    android:layout_gravity="left"
                    android:layout_alignParentLeft="true"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/button_selector"
                    android:textColor="@color/colorPrimary"
                    android:text="Previous" />

                <Button
                    android:id="@+id/button_next"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="2px"
                    android:layout_gravity="right"
                    android:layout_alignParentRight="true"
                    android:background="@drawable/button_selector"
                    android:textColor="@color/colorPrimary"
                    android:text="Next" />

            </RelativeLayout>

        </LinearLayout>
    </ScrollView>
        </LinearLayout>


现在,它可以正确地用于大内容,但对于短内容,按钮会显示在内容的正下方,我希望它们显示在屏幕的底部,将滚动视图扩展到活动,并在diff==00时使按钮可见。设置butoon不可见仅在schroll整页时才可见。希望它能帮助你

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) 
{
    // Grab the last child placed in the ScrollView, we need it to determinate the bottom position.
    View view = (View) getChildAt(getChildCount()-1);

    // Calculate the scrolldiff
    int diff = (view.getBottom()-(getHeight()+getScrollY()));

    // if diff is zero, then the bottom has been reached
    if( diff == 0 )
    {

       // make button visible here
        // notify that we have reached the bottom
        Log.d(ScrollTest.LOG_TAG, "MyScrollView: Bottom has been reached" );
    }

    super.onScrollChanged(l, t, oldl, oldt);
}

您可以使用以下结构来实现视图:

<RelativeLayout
.
.
.>
<LinearLayout
.
.
align_parent_top=true
id = top_layout>
//Content
</LinearLayout>

<WebView
.
.
layout_above = bottom_layout
layout_below = top_layout
.
id = web_view/>

<LinearLayout
.
.
.
id = bottom_layout
align_parent_bottom=true>
//content
</LinearLayout>

</RelativeLayout>

//内容
//内容
希望这对您有所帮助:)