如何显示2次在1活动(机器人)? [英] How do I display 2 views in 1 activity (android)?
问题描述
假设我有一个web视图打开:
Suppose I have a webview open:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
main_webv = (WebView) findViewById(R.id.mainwebview);
main_webv.setWebViewClient(new HelloWebViewClient());
main_webv.getSettings().setJavaScriptEnabled(true);
main_webv.getSettings().setSupportZoom(false);
main_webv.addJavascriptInterface(new HelloJavascriptInterface(),"hello");
main_webv.setWebChromeClient(new HelloWebChromeClient());
main_webv.loadUrl(SPLASH);
main_webv.setVisibility( 4 );
setContentView(R.layout.main_list);
main_listv = (ListView) findViewById(R.id.mainlistview);
}
我只是想创建一个的ListView 这上面的WebView(包括它......但罗纳尔多,也很想让web视图运行)。我可以打开和关闭的意见。 谢谢你。
I simply want to create a ListView above this webview (covering it up...but sitll allowing the webview to run). I could toggle the views on and off. Thanks.
推荐答案
您可以使用的FrameLayout ;这样既视图将被布置在另一个之上。然后,您可以使用 View.setVisibility(..)
法切换自己的知名度。
You can use FrameLayout; that way both the Views will be arranged on top of another. You can then toggle their visibility using the View.setVisibility(..)
method.
这是我的布局XML(weblister.xml):
This is my layout XML(weblister.xml):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="@+id/list_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</FrameLayout>
现在,我创建活动,将有两个ListView和的WebView在浏览层次结构,但其中只有一个是可见的:
Now, I create an Activity which will have both ListView and WebView in its View heirarchy but only one of them would be Visible:
public class WebAct extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.weblister);
//setup listview
ListView listView = (ListView) findViewById(R.id.list_view);
listView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
new String[]{"One","Two"}){
});
// setup web view
WebView webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setSupportZoom(false);
webView.loadUrl("http://www.google.com");
// set visibility
listView.setVisibility(View.INVISIBLE);
webView.setVisibility(View.VISIBLE);
}
}
注意:的code可能是不完整的,但我希望它传达我的观点对你
Note: The code might not be complete but I hope it does convey my point to you.
这篇关于如何显示2次在1活动(机器人)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!