#android #tabs #webview
#Android #вкладки #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");
}
по сути, единственное, что я хочу прокручивать по горизонтали, — это вкладки, все остальное я хочу отображать нормально
можно ли сделать то, что я пытаюсь сделать?
Ответ №1:
(извините за предыдущий ответ, слишком быстро читал ваши материалы)
Для вашего HorizontalScrollView
layout_width
и WebView
-х layout_width
-х wrap_content
-х установлено значение, равное,,. wrap_content
Значение не особенно хорошо работает с объектами, которые могут прокручиваться в этом направлении. Предполагая, что в этом макете больше ничего нет, попробуйте переключить оба из них на layout_width
быть fill_parent
(или match_parent
).
Комментарии:
1. я по-прежнему получаю те же результаты, когда фактическая активность, которую я хочу отобразить в webview, отображается некорректно. возможно, у вас есть какие-либо другие предложения о том, как я могу этого добиться. весь веб-просмотр — это инструкция с картинками о том, как настроить эту часть программы