2011-04-06 45 views
0

我在水平滾動視圖中設置了一些標籤,我試圖顯示所選標籤的活動的webview,而不是webview是它顯示的屏幕寬度tabview的寬度,基本上否定了我想用滾動視圖中的選項卡完成的操作。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

(抱歉前面的答案,在讀你的東西太快)

HorizontalScrollViewlayout_width和你WebViewlayout_width都設置爲wrap_contentwrap_content值不適用於可以在該方向上滾動的事物。假設此佈局中沒有其他內容,請嘗試將這兩個layout_width切換爲fill_parent(或match_parent)。

+0

我仍然得到相同的結果,我想要顯示webview的實際活動沒有正確顯示。你可能有任何其他建議,我可以如何實現這一點。所有的網絡視圖,是指導圖片如何設置程序的這一部分 – tyczj 2011-04-06 23:07:03