0

enter image description here創建自定義視圖

我對着在設計這個程序,標籤與自定義視圖,其中兩個選項卡是具有3元可第一標籤中的問題的應用程序選項卡,有3個子元素,每個元素每個子元素具有3個子元素。第二個標籤,我必須顯示帶有標籤的圖像。

回答

0
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 


    <TabHost 
     android:id="@+id/tabHost" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" /> 

      <FrameLayout 
       android:id="@android:id/tabcontent" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

       <RelativeLayout 
        android:id="@+id/first_tab" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 
       //YOUR FIRST VIEW CREATE OR INCLUDE VIEW 
        <include 
        android:id="@+id/first_tab" 
        layout="@layout/first_tab" /> 

       </RelativeLayout> 

       <RelativeLayout 
        android:id="@+id/secend_tab" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        //YOUR SECEND VIEW CREATE OR INCLUDE VIEW 
        <include 
        android:id="@+id/secend_tab" 
        layout="@layout/secend_tab" /> 
       </RelativeLayout> 

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

和代碼在您的活動,對話等

TabHost host = (TabHost) findViewById(R.id.tabHost); 
    host.setup(); 

    //Tab 1 
    TabHost.TabSpec spec = host.newTabSpec("firstTab"); 
    spec.setContent(R.id.first_tab); 
    spec.setIndicator("TABE ONE"); 
    host.addTab(spec); 


    //Tab 2 
    spec = host.newTabSpec("secendTab"); 
    spec.setContent(R.id.secend_tab); 
    spec.setIndicator("TAB TWO"); 
    host.addTab(spec); 
0

很簡單。爲您的選項卡在xml中構造一個佈局。然後它充氣,並呼籲

getTabAt(x).setCustomView(View v); 

的代碼是這樣:

TextView tabOne = (TextView)LayoutInflater.from(this).inflate(R.layout.custom_tab, null); 
    tabOne.setText("ONE"); 
    tabOne.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_tab_favourite, 0, 0); 
    tabLayout.getTabAt(0).setCustomView(tabOne); 
0

首先對你的標籤

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      app:tabMode="fixed" 
      app:tabGravity="fill"/> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.view.ViewPager 
     android:id="@+id/viewpager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
</android.support.design.widget.CoordinatorLayout> 

http://www.androidhive.info/2015/09/android-material-design-working-with-tabs/

創建tablayout然後你的第一個選項卡需要expandablelistview

http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/

+0

是否解決了 –