我在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>
现在它可以正常使用大内容但是对于简短的内容,按钮会显示在内容的正下方,我希望它们位于屏幕的底部
答案 0 :(得分:0)
将ScrollView扩展为活动,并在diff == 00时设置按钮可见,只有当schroll整页时才能看到butoon invible。希望它会对你有所帮助。
@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);
}
答案 1 :(得分:0)
您可以使用以下结构来实现视图:
<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>
希望这会对你有所帮助.. :)