我對着在設計這個程序,標籤與自定義視圖,其中兩個選項卡是具有3元可第一標籤中的問題的應用程序選項卡,有3個子元素,每個元素每個子元素具有3個子元素。第二個標籤,我必須顯示帶有標籤的圖像。
Q
創建自定義視圖
0
A
回答
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/
相關問題
- 1. 創建自定義視圖
- 2. 創建自定義視圖
- 3. 創建自定義視圖?
- 4. 創建自定義視圖
- 5. 自定義創建的視圖
- 6. 創建一個自定義視圖組
- 7. 在視圖內創建自定義tableviewcell
- 8. 創建自定義視圖時出錯
- 9. 創建自定義列表視圖
- 10. 創建自定義視圖需要Android
- 11. Catel自定義視圖創建
- 12. 從xml創建自定義視圖
- 13. 超慢創建自定義視圖
- 14. 創建Android自定義視圖
- 15. 創建自定義視圖2011錯誤
- 16. 創建自定義尺寸視圖Xamarin.iOS
- 17. 在Android中創建自定義視圖
- 18. 創建自定義視圖對象
- 19. 創建自定義視圖,Android Studio
- 20. 創建自定義視圖的步驟
- 21. iOS 5創建自定義視圖
- 22. Android:自定義視圖創建教程
- 23. 在iOS中創建自定義視圖
- 24. 創建自定義複合視圖
- 25. 創建自定義模糊視圖
- 26. Android:創建自定義視圖
- 27. 如何創建像自定義列表視圖的自定義圖像視圖?
- 28. 創建自定義視圖的自定義列表
- 29. 如何在Android的自定義視圖中創建自定義視圖?
- 30. 創建視圖定義器
是否解決了 –