0

enter image description hereカスタムビュー私はこのアプリ、二つのタブが3要素を持つ利用できる最初のタブのカスタムビュー</strong>、と<strong>タブを設計する上で問題に直面しています

を持つアプリのタブを作成し、各要素は3つのサブ要素を持ち、各サブ要素は3つのサブ要素を有する。 2番目のタブは、URLからラベル付きの画像を表示する必要があります。

あなたの活動の

答えて

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

解決済み –

関連する問題