Layout file
<? Xml Version = "1.0" encoding = "UTF-8" ?> < TabHost xmlns: Android = "http://schemas.android.com/apk/res/android" xmlns: App = "HTTP: // schemas .android.com / APK / RES-Auto " xmlns: Tools =" http://schemas.android.com/tools " Android: layout_width =" match_parent " Android: layout_height =" match_parent " Tools: context =." the MainActivity " Android: Orientation = "Vertical Number of" Android: the above mentioned id = "@ Android: the above mentioned id / TabHost" > <-! tab layout which requires two files: one is above the label layout, a layout is the following content -> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TabWidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content"> </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> </LinearLayout> </TabHost>
Two sub-layout files
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/left" > <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/a" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/right" > <ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/b" /> </LinearLayout>
java call
package com.example.myhighuiiiii; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.LayoutInflater; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Spinner; import android.widget.TabHost; import android.widget.Toast; public class MainActivity extends AppCompatActivity { TabHost tabHost = null; @Override protected void onCreate(Bundle savedInstanceState) { Super .onCreate (savedInstanceState); the setContentView (R.layout.activity_main); TabHost = (TabHost) the findViewById (android.R.id.tabhost); tabHost.setup (); // load two tabs tab1, the layout tab2 file LayoutInflater = LayoutInflater.from inflater so that ( the this ); Inflater.inflate ( R.layout.tab1, tabHost.getTabContentView () ); Inflater.inflate ( R.layout.tab2, tabHost.getTabContentView () ); // add a first tabs tabHost.addTab ( tabHost.newTabSpec ( "tab1" ) .setIndicator ( "Selection expression" ) .setContent (R.id.left)); // add a second tab tabHost.addTab ( tabHost.newTabSpec ( "TAB2" ) .setIndicator ( "Submission Selection" ) . the setContent (R.id.right)); } }