веб-представление не отображается правильно во вкладках - PullRequest
0 голосов
/ 06 апреля 2011

У меня есть несколько вкладок, настроенных в режиме горизонтальной прокрутки, и я пытаюсь отобразить веб-просмотр активности выбранной вкладки, но вместо веб-просмотра, являющегося шириной экрана, он отображает ширину просмотра вкладок, в основномотрицание того, что я пытаюсь выполнить с помощью вкладок в представлении с прокруткой.

Если я вложу веб-просмотр с вкладками, он покажет, как я хочу, но это будет просто показ веб-просмотра и не запуск фактической активности

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_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;
}
}

и активность с веб-просмотром

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");   
}

в основном единственное, что я хочу быть в горизонтальном положениипрокрутка - это вкладки, все остальное, что я хочу отображать нормально

можно ли сделать то, что я пытаюсь сделать?

1 Ответ

0 голосов
/ 06 апреля 2011

(извините за предыдущий ответ, читал ваши материалы слишком быстро)

Ваши HorizontalScrollView layout_width и WebView layout_width установлены на wrap_content.Значение wrap_content не особенно хорошо работает с вещами, которые могут прокручиваться в этом направлении.Предполагая, что в этом макете больше ничего нет, попробуйте переключить оба из этих layout_width на fill_parent (или match_parent).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...