English 中文(简体)
Anders-Customized TabHost
原标题:Android-Customized TabHost
  • 时间:2011-01-07 05:52:55
  •  标签:
  • android

我无法通过定制的刺.。 请任何人帮助我。 我试图通过习俗表态。 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

问题回答

希 腊 如果你想在单张表格中转开活动,就可以创建活动小组,那么,这将充分利用这一手段创造成本。

public class MyTabHost extends TabActivity 
{   
public static TabHost tabHost;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Resources res = getResources(); // Resource object to get Drawables
    tabHost = getTabHost();  // The activity TabHost 
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab



    intent = new Intent().setClass(this, MyFirst1.class);
    spec = tabHost.newTabSpec("MyFirst1").setIndicator("",res.getDrawable(R.drawable.image1)).setContent(intent);
    tabHost.addTab(spec);


    intent = new Intent().setClass(this, MyFirst2.class);
    spec = tabHost.newTabSpec("MyFirst2").setIndicator("",res.getDrawable(R.drawable.image2)).setContent(intent);
    tabHost.addTab(spec);


    tabHost.setCurrentTab(0);
iii

iii





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签