簡體   English   中英

如何在Android的TabHost中添加單獨的布局和類?

[英]How to add seperate layout and class to TabHost in android?

我的基本布局如下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"   
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="lk.abanservice.shankan.abansserviceapp.CheckStatus">

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <LinearLayout
                android:id="@+id/checkSerach"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

            </LinearLayout>

            <LinearLayout
                android:id="@+id/checkDisplayAll"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

            </LinearLayout>

        </FrameLayout>
    </LinearLayout>
</TabHost>

所以我需要添加以下單獨的文件和類

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" 
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/title_request"
    android:id="@+id/textViewTitleRequestt"
    android:textStyle="bold" />

我嘗試了幾種方法來做到這一點,可以使用TabActivity做到這一點,但已從android 11中刪除。有人對此有解決方案嗎?

我想開發以下界面

在此處輸入圖片說明 在此處輸入圖片說明

這是Tab Host示例。.根據您的要求更改變量和類名。

MainActivity.java

public class MainActivity extends TabActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    TabHost tab = getTabHost();

    TabSpec news = tab.newTabSpec("New");
    news.setIndicator("Check New Job");
    Intent intent = new Intent(MainActivity.this,First.class);
    news.setContent(intent);

    TabSpec old = tab.newTabSpec("Old");
    old.setIndicator("Check Old Job");
    Intent intent_old = new Intent(MainActivity.this,Second.class);
    old.setContent(intent_old);

    tab.addTab(news);
    tab.addTab(old);
    }
 }

activity_main.java

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </FrameLayout>
  </LinearLayout>

</TabHost>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM