我在水平滚动视图中设置了几个标签,我试图显示所选标签的活动的webview,但是webview的宽度不是webview,而是显示tabview的宽度,基本上否定我想用滚动视图中的选项卡完成的任务。
如果我使用标签嵌入webview,它将显示我想要的方式,但这只是显示webview而不是开始实际活动
标签xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="vertical"
android:layout_height="fill_parent" android:layout_width="fill_parent">
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="750dp"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<View android:layout_width="fill_parent" android:layout_height="0.5dip"
android:background="#000" />
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginLeft="0dip" android:layout_marginRight="0dip" />
<View android:layout_width="fill_parent" android:layout_height="2dip"
android:background="#696969" />
<View android:layout_width="fill_parent" android:layout_height="2dip"
android:background="#000" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
</LinearLayout>
</HorizontalScrollView>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView2"
android:layout_height="fill_parent"
android:layout_width="wrap_content"></WebView>
</LinearLayout>
tabactivity
public class Tabs extends TabActivity {
private TabHost mTabHost;
private void setupTabHost() {
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
}
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setupTabHost();
mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
Intent intent;
intent = new Intent().setClass(this, Main.class);
setupTab(new TextView(this), "Tab 1",intent);
intent = new Intent().setClass(this, SmsMain.class);
setupTab(new TextView(this), "Tab 2",intent);
intent = new Intent().setClass(this, BatteryMain.class);
setupTab(new TextView(this), "Tab 3",intent);
intent = new Intent().setClass(this, MailMain.class);
setupTab(new TextView(this), "Tab 4",intent);
WebView browser = (WebView) findViewById(R.id.webView2); //this way displays fine but its not starting an activity
browser.loadUrl("file:///android_asset/about.html");
}
private void setupTab(final View view, final String tag, Intent intent) {
View tabview = createTabView(mTabHost.getContext(), tag);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent);
mTabHost.addTab(setContent);
}
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
}
和使用webview的活动
public class Main extends Activity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main_webview);
Log.d("Debug", "main oncreate");
WebView browser = (WebView)findViewById(R.id.webView1); //displays the whole tabview
//setContentView(browser);
browser.loadUrl("file:///android_asset/about.html");
}
基本上我唯一想要横向滚动的是标签,我想要正常显示的其他内容
可以做我想做的事情吗?
答案 0 :(得分:0)
(对以前的回答感到抱歉,过快地读你的东西)
您的HorizontalScrollView
的{{1}}和layout_width
的{{1}}都设置为WebView
。 layout_width
值对于可以向该方向滚动的内容不起作用。假设此布局中没有其他内容,请尝试将这两个wrap_content
切换为wrap_content
(或layout_width
)。