Android WebView,下面有一行按钮
我正在发疯,试图找出如何使这个简单的布局工作。我希望在一行居中按钮的顶部有一个webview。如果我指定一个特定的dp,比如400dp,我可以看到屏幕顶部的webview和底部的按钮。但是,对于多个屏幕大小,这并不能很好地扩展。如果我使用“fill_parent”,那么我永远看不到webview下面的按钮 我只是想要一个布局,将始终放置在屏幕底部的按钮(而不是从屏幕上滚动),并让webview占据其上方的其余空间。我总体上使用相对布局,因为我希望在加载webview时,进度指示器位于屏幕中央 这是我的密码:Android WebView,下面有一行按钮,android,layout,webview,uibutton,Android,Layout,Webview,Uibutton,我正在发疯,试图找出如何使这个简单的布局工作。我希望在一行居中按钮的顶部有一个webview。如果我指定一个特定的dp,比如400dp,我可以看到屏幕顶部的webview和底部的按钮。但是,对于多个屏幕大小,这并不能很好地扩展。如果我使用“fill_parent”,那么我永远看不到webview下面的按钮 我只是想要一个布局,将始终放置在屏幕底部的按钮(而不是从屏幕上滚动),并让webview占据其上方的其余空间。我总体上使用相对布局,因为我希望在加载webview时,进度指示器位于屏幕中央 这
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ProgressBar android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="@android:style/Widget.ProgressBar.Inverse"
/>
<WebView android:layout_width="fill_parent"
android:id="@+id/webview"
android:layout_alignParentTop="true"
android:layout_height="400dp"
android:layout_weight="1">
</WebView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/webview"
>
<Button android:text="Browse"
android:id="@+id/btnBrowse"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:drawableTop="@drawable/brouse"
android:textSize="9dp"
/>
<Button android:text="Account"
android:id="@+id/btnAccount"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:drawableTop="@drawable/account"
android:layout_toRightOf="@+id/btnBrowse"
android:textSize="9dp"
/>
<Button android:text="Contact"
android:id="@+id/btnContact"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1.0"
android:drawableTop="@drawable/contact"
android:layout_toRightOf="@+id/btnAccount"
android:textSize="9dp"
/>
<Button android:text="Quote"
android:id="@+id/btnQuote"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:drawableTop="@drawable/custom"
android:layout_toRightOf="@+id/btnContact"
android:textSize="9dp"
/>
</LinearLayout>
</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">
<ProgressBar android:id="@+id/progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="@android:style/Widget.ProgressBar.Inverse"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="9.0"
android:layout_alignParentTop="true">
</WebView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"
android:layout_alignParentBottom="true"
>
<Button android:text="Browse"
android:id="@+id/btnBrowse"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:drawableTop="@drawable/brouse"
android:textSize="9dp"
/>
<Button android:text="Account"
android:id="@+id/btnAccount"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:drawableTop="@drawable/account"
android:textSize="9dp"
/>
<Button android:text="Contact"
android:id="@+id/btnContact"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentBottom="true"
android:layout_weight="1.0"
android:drawableTop="@drawable/contact"
android:textSize="9dp"
/>
<Button android:text="Quote"
android:id="@+id/btnQuote"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:drawableTop="@drawable/custom"
android:textSize="9dp"
/>
</LinearLayout>
</LinearLayout>
将网络视图相对置于线性布局之上,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ProgressBar android:id="@+id/progressbar"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="@android:style/Widget.ProgressBar.Inverse" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:layout_below="@id/webview" android:id="@+id/buttonLayout">
<Button android:text="Browse" android:id="@+id/btnBrowse"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_weight="1.0" android:layout_alignParentBottom="true"
android:drawableTop="@drawable/brouse" android:textSize="9dp" />
<Button android:text="Account" android:id="@+id/btnAccount"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_weight="1.0" android:layout_alignParentBottom="true"
android:drawableTop="@drawable/account" android:layout_toRightOf="@+id/btnBrowse"
android:textSize="9dp" />
<Button android:text="Contact" android:id="@+id/btnContact"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignParentBottom="true" android:layout_weight="1.0"
android:drawableTop="@drawable/contact" android:layout_toRightOf="@+id/btnAccount"
android:textSize="9dp" />
<Button android:text="Quote" android:id="@+id/btnQuote"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_weight="1.0" android:layout_alignParentBottom="true"
android:drawableTop="@drawable/custom" android:layout_toRightOf="@+id/btnContact"
android:textSize="9dp" />
</LinearLayout>
<WebView android:layout_width="fill_parent" android:id="@+id/webview"
android:layout_above="@id/buttonLayout" android:layout_height="fill_parent" />
</RelativeLayout>
线性布局
放置在屏幕底部网络视图
置于线性布局
上方只需从中调整答案即可 我理解这一点,因为
WebView
需要相对于LinearLayout
进行配置,因为按钮具有预定义的大小,WebView
可以猜测它还剩下多少空间。
如果您想做相反的操作(相对于WebView
的按钮),WebView
以占据整个屏幕开始,然后按钮不能再移动到任何地方
为了清楚起见,我只包含了布局的相关部分。关键是使用WebView
上的android:layout\u,而不是LinearLayout上的android:layout\u
:
<WebView android:layout_width="fill_parent"
android:id="@+id/webview"
android:layout_above="@id/buttons"
android:layout_height="fill_parent">
</WebView>
<LinearLayout
android:orientation="horizontal"
android:id="@+id/buttons"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button android:text="Browse"
android:id="@+id/btnBrowse"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1.0"
android:layout_alignParentBottom="true"
android:textSize="9dp"/>
<!-- more buttons ... -->
</LinearLayout>
TQM到jkhouw1,从您的代码中获得帮助,我想与大家分享我制作的所有布局;
完整的代码在这里-
好的,下面是代码:
上图有两行按钮:一行在顶部,一行在底部。中间是WebVIEW。
这是我的GitHub帐户,您可以在其中下载源代码:
否则,以下是应用程序细分:
Java代码(AndroidMobileAppSampleActivity.Java):
我有两个XML布局。一个是主网页,另一个是我在主网页中预先制作的菜单。
XML布局“app_page.XML”:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/page_weekly_items_options_menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#d4dbe1"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/share"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedShare"></ImageView>
<ImageView
android:id="@+id/left_arrow"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedLeftArrow"></ImageView>
<ImageView
android:id="@+id/right_arrow"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedRightArrow"></ImageView>
<ImageView
android:id="@+id/notifications_pageweeklyitem"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedNotificationsPageWeeklyItem"></ImageView>
<ImageView
android:id="@+id/favorites_pageweeklyitem"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedFavoritesPageWeeklyItem"></ImageView>
</LinearLayout>
<RelativeLayout
android:id="@+id/webcontent_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@id/page_weekly_items_options_menu">
<WebView
android:id="@+id/webcontent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/menu"
></WebView>
<include
android:id="@+id/menu"
layout="@layout/bottom_menu"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_weight="1"
/>
</RelativeLayout>
</RelativeLayout>
另一个XML布局是“bottom_menu.XML”:
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottom_scroll_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >
<!-- This layout is used by activity_main.xml.
It is part of the main home page -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#17528c"
android:orientation="horizontal" >
<ImageView
android:id="@+id/Weekly"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedWeekly" >
</ImageView>
<ImageView
android:id="@+id/Search"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedSearch" >
</ImageView>
<ImageView
android:id="@+id/Favorites"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedFavorites" >
</ImageView>
<ImageView
android:id="@+id/Notifications"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedNotifications" >
</ImageView>
<ImageView
android:id="@+id/Profile"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedProfile" >
</ImageView>
<ImageView
android:id="@+id/About"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedAbout" >
</ImageView>
</LinearLayout>
</HorizontalScrollView>
Android清单(以防有人忘记互联网许可):
完整的代码可以在这里找到,第3行:必须是android:layout_以上=“@+id/按钮”(缺少加号)
package com.gene;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.gene.R;
public class AndroidMobileAppSampleActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app_page);
WebView mainWebView = (WebView) findViewById(R.id.webcontent);
WebSettings webSettings = mainWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mainWebView.setWebViewClient(new MyCustomWebViewClient());
mainWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
mainWebView.loadUrl("http://www.google.com");
}
private class MyCustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/page_weekly_items_options_menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#d4dbe1"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/share"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedShare"></ImageView>
<ImageView
android:id="@+id/left_arrow"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedLeftArrow"></ImageView>
<ImageView
android:id="@+id/right_arrow"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedRightArrow"></ImageView>
<ImageView
android:id="@+id/notifications_pageweeklyitem"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedNotificationsPageWeeklyItem"></ImageView>
<ImageView
android:id="@+id/favorites_pageweeklyitem"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedFavoritesPageWeeklyItem"></ImageView>
</LinearLayout>
<RelativeLayout
android:id="@+id/webcontent_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@id/page_weekly_items_options_menu">
<WebView
android:id="@+id/webcontent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/menu"
></WebView>
<include
android:id="@+id/menu"
layout="@layout/bottom_menu"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_weight="1"
/>
</RelativeLayout>
</RelativeLayout>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bottom_scroll_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >
<!-- This layout is used by activity_main.xml.
It is part of the main home page -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#17528c"
android:orientation="horizontal" >
<ImageView
android:id="@+id/Weekly"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedWeekly" >
</ImageView>
<ImageView
android:id="@+id/Search"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedSearch" >
</ImageView>
<ImageView
android:id="@+id/Favorites"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedFavorites" >
</ImageView>
<ImageView
android:id="@+id/Notifications"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedNotifications" >
</ImageView>
<ImageView
android:id="@+id/Profile"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedProfile" >
</ImageView>
<ImageView
android:id="@+id/About"
android:layout_width="60dp"
android:layout_height="50dp"
android:background="@drawable/icon"
android:clickable="true"
android:onClick="userClickedAbout" >
</ImageView>
</LinearLayout>
</HorizontalScrollView>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tscolari.mobile_sample"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AndroidMobileAppSampleActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>