我无法通过定制的刺.。 请任何人帮助我。 我试图通过习俗表态。 java to firsttab.java which contained the firsttab.xml as setcontentview.
Main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<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:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<View android:layout_width="fill_parent" android:layout_height="0.5dip"
android:background="#ff0000" />
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginLeft="0dip" android:layout_marginRight="0dip" />
<View android:layout_width="fill_parent" android:layout_height="2dip"
android:background="#696969" />
<View android:layout_width="fill_parent" android:layout_height="2dip"
android:background="#000" />
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<include layout="@layout/firsttab"/>
</FrameLayout>
</LinearLayout>
</TabHost>
CustomTabHost.java
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
import android.content.Intent;
public class CustomTabActivity extends Activity {
private TabHost mTabHost;
private void setupTabHost() {
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
iii
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// construct the tabhost
requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.main);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.headphones);
setupTabHost();
mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
setupTab1(new TextView(this), "Showcase");
setupTab2(new TextView(this), "Catalogue");
iii
private void setupTab1(final View view, final String tag) {
View tabview = createTabView(mTabHost.getContext(), tag);
TabSpec setContent1 = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
public View createTabContent(String tag) {
return view;iii
iii);
mTabHost.addTab(setContent1);
iii
private void setupTab2(final View view, final String tag) {
View tabview = createTabView(mTabHost.getContext(), tag);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
public View createTabContent(String tag) {
return view;iii
iii);
mTabHost.addTab(setContent);
iii
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
iii
iii
firsttab.xml
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="20dip"
android:id="@+id/relative">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/New_Release"
android:textSize="15dip"
android:typeface="serif"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Featured_Artist"
android:textSize="15dip"
android:typeface="serif"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Crew_Picks"
android:textSize="15dip"
android:typeface="serif"
android:layout_weight="1"/>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="20dip"
android:layout_below="@id/relative">
<ImageView
android:layout_width="55dip"
android:layout_height="75dip"
android:layout_weight="1"
android:src="@drawable/da"
android:padding="2dip"
android:id="@+id/image1"/>
<ImageView
android:layout_width="55dip"
android:layout_height="75dip"
android:layout_toRightOf="@id/image1"
android:layout_weight="1"
android:src="@drawable/dd"
android:padding="2dip"
android:id="@+id/image2"
/>
<ImageView
android:layout_width="100dip"
android:layout_height="148dip"
android:layout_toRightOf="@id/image2"
android:src="@drawable/dd"
android:padding="2dip"
android:id="@+id/image3"/>
<ImageView
android:layout_width="55dip"
android:layout_height="75dip"
android:src="@drawable/da"
android:layout_weight="1"
android:padding="2dip"
android:id="@+id/image4"
android:layout_alignParentRight="true"/>
<ImageView
android:layout_width="55dip"
android:layout_height="75dip"
android:layout_toLeftOf="@id/image4"
android:padding="2dip"
android:layout_weight="1"
android:src="@drawable/dd"
android:id="@+id/image5"
/>
<ImageView
android:layout_width="55dip"
android:layout_height="75dip"
android:layout_below="@id/image1"
android:padding="2dip"
android:layout_weight="1"
android:id="@+id/image6"
android:src="@drawable/dd"/>
<ImageView
android:layout_width="55dip"
android:layout_height="75dip"
android:layout_below="@id/image2"
android:layout_toRightOf="@id/image6"
android:padding="2dip"
android:layout_weight="1"
android:id="@+id/image7"
android:src="@drawable/da"
/>
<ImageView
android:layout_width="55dip"
android:layout_height="75dip"
android:layout_alignParentRight="true"
android:layout_below="@id/image4"
android:padding="2dip"
android:layout_weight="1"
android:id="@+id/image9"
android:src="@drawable/da"
/>
<ImageView
android:layout_width="55dip"
android:layout_height="75dip"
android:layout_toLeftOf="@id/image9"
android:padding="2dip"
android:layout_below="@id/image5"
android:layout_weight="1"
android:id="@+id/image8"
android:src="@drawable/dd"
/>
</RelativeLayout>
</RelativeLayout>
firsttab.java
public class firsttab extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* First Tab Content */
setContentView(R.layout.firsttab);
iii
iii