开发者

webview not displaying correctly in tabs

I have a few tabs set up in a horizontal scroll view and i am trying to display a webview of an activity of the tab selected but instead of the webview being the width of the screen it displays the width of the tabview, basically negating what i am trying to accomplish with the tabs in a scroll view.

If I nest a webview in with the tabs it will display how i want but that would be just showing a webview and not starting an actual activity

tabs 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_con开发者_C百科tent"
            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;
}
}

and activity with a 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");   
}

basically the only thing i want to be horizontally scrolling is the tabs, everything else i want to display normally

can what i am trying to do be done?


(sorry about previous answer, was reading your stuff too quickly)

Your HorizontalScrollView's layout_width and your WebView's layout_width are both set to wrap_content. The wrap_content value does not work especially well with things that can scroll in that direction. Assuming there is nothing else in this layout, try switching both of those layout_width to be fill_parent (or match_parent).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜