Sekmeli mizanpajlı bir Android uygulaması geliştiriyorum. Google's tutorial suggested gibi yeni bir etkinlik oluşturmadığı yere sahibim, ancak bunu yalnızca her bir sekmeyi tıklarken içeriğimin gösterilmesini sağlamak için yaptım. Şu anda hangi sekmenin aktif olduğuna bakmaksızın sadece siyahı gösterir. Android Sekmeli Layout setContent
aşağıdaki
onun en yeni haliyle benim kodudur:Main.java
public class Main extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
// add orders tab
spec = tabHost.newTabSpec("orders").setIndicator("Orders",
res.getDrawable(R.drawable.flash_36))
.setContent(R.id.ordersLayout);
tabHost.addTab(spec);
// add positions tab
spec = tabHost.newTabSpec("positions").setIndicator("Positions",
res.getDrawable(R.drawable.small_tiles_36))
.setContent(R.id.positionsLayout);
tabHost.addTab(spec);
// add strategies tab
spec = tabHost.newTabSpec("strategies").setIndicator("Strategies",
res.getDrawable(R.drawable.cards_36))
.setContent(R.id.strategiesLayout);
tabHost.addTab(spec);
// add account tab
spec = tabHost.newTabSpec("account").setIndicator("Account",
res.getDrawable(R.drawable.seal_36))
.setContent(R.id.accountLayout);
tabHost.addTab(spec);
tabHost.setCurrentTab(1);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:padding="5dp">
<include layout="@layout/orders"/>
<include layout="@layout/positions"/>
<include layout="@layout/strategies"/>
<include layout="@layout/account"/>
</FrameLayout>
</LinearLayout>
</TabHost>
Account.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/accountLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:text="Account Information"
android:id="@+id/accountLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
Siparişler.xml Sadece bu ikisi dahil ediyorum
, onlar LinearLayout en android için uygun kimlikleri ile tüm tam aynı şunlardır: id parametresi.
Siparişleri
Pozisyonlar Tab
Tab
:<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/ordersLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:text="Working Orders"
android:id="@+id/ordersLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
Ve burada sekmeler arasında geçiş yapıldığında ne alıyorum bir ekran görüntüsü var
Hem öykünücüsü hem de yeni bir Samsung Galaxy için bu doğrudur ve bu arada öneriyorum, herhangi bir fikir var mı?
+1. – Subby