2012-03-28 51 views
0

如何使這種標籤在Android的[http://i.stack.imgur.com/rIbUX.png]如何實現自定義選項卡主機中的Android

只是提到他看到的重疊區域時,你點擊標籤,重疊改變。

這裏是一個中文版我想這就是我想要的例子,但是他們沒有提供完整的代碼,我也不知道如何繼續這個項目。

http://www.oschina.net/question/54100_29061

我目前使用Android 3.2及ICS 4+實施這個項目,所以歡迎,如果這是可能實現competible與Framgment。


我終於自己做出瞭解決方案。我只是離開本地選項卡主機的實施,組成我自己的。

這裏是屏幕截圖: [http://i.stack.imgur.com/1mXLZ.png]

這裏是活動的代碼:

import android.app.Activity; 
import android.graphics.drawable.Drawable; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.ImageView; 
import android.widget.TextView; 

public class PelesysTabHostActivity extends Activity { 
private ImageView ib1, ib2, ib3, last; 
private Drawable pressed, released; 
private TextView tv,tv1,tv2,tv3; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
    ib1 = (ImageView) this.findViewById(R.id.imageView1); 
    ib2 = (ImageView) this.findViewById(R.id.imageView2); 
    ib3 = (ImageView) this.findViewById(R.id.imageView3); 
    tv = (TextView) this.findViewById(R.id.textView1); 
    tv1= (TextView) this.findViewById(R.id.textView11); 
    tv2= (TextView) this.findViewById(R.id.textView22); 
    tv3= (TextView) this.findViewById(R.id.textView33); 

    pressed = getResources().getDrawable(R.drawable.ui_table_tab_button); 
    released = getResources().getDrawable(
      R.drawable.ui_table_tab_button_disabled); 
    ib1.setImageDrawable(pressed); 
    last = ib1; 

    ib1.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      last.setImageDrawable(released); 
      ib1.setImageDrawable(pressed); 
      last = ib1; 
      tv.setText("I am super 1"); 
      ib1.bringToFront(); 
      tv1.bringToFront(); 
     } 
    }); 

    ib2.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      last.setImageDrawable(released); 
      ib2.setImageDrawable(pressed); 
      last = ib2; 
      tv.setText("TWO!!! I am super 2"); 
      ib2.bringToFront(); 
      tv2.bringToFront(); 
     } 
    }); 

    ib3.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      last.setImageDrawable(released); 
      ib3.setImageDrawable(pressed); 
      last = ib3; 
      tv.setText(" III !!! I am super 3"); 
      ib3.bringToFront(); 
      tv3.bringToFront(); 
     } 
    }); 

} 
} 

這裏是佈局文件我用(main.xml中)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<RelativeLayout 
    android:id="@+id/relativeLayout2" 
    android:layout_width="fill_parent" 
    android:layout_height="330dp" 
    android:layout_alignParentLeft="true" 
    android:layout_centerVertical="true" > 

    <ImageView 
     android:id="@+id/imageView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:src="@drawable/ui_table_bg_coursedetail" /> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:text="Large Text" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="#000000" /> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/relativeLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/relativeLayout2" 
    android:layout_alignParentLeft="true" 
    android:layout_marginLeft="326dp" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:src="@drawable/ui_table_tab_button_disabled" /> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="90dp" 
     android:src="@drawable/ui_table_tab_button_disabled" /> 

    <ImageView 
     android:id="@+id/imageView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="180dp" 
     android:src="@drawable/ui_table_tab_button_disabled" /> 

    <TextView 
     android:id="@+id/textView11" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView1" 
     android:layout_marginLeft="50dp" 
     android:text="1" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#000000" /> 

    <TextView 
     android:id="@+id/textView22" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView2" 
     android:layout_marginLeft="50dp" 
     android:text="2" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#000000" /> 

    <TextView 
     android:id="@+id/textView33" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView3" 
     android:layout_marginLeft="50dp" 
     android:text="3" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#000000" /> 
</RelativeLayout> 

+0

在這裏,您可以通過實現自定義的TabHost來獲得很好的示例:http://www.anddev.org/code-snippets-for-android-f33/iphone-tabs-for-android -t14678.html – Emran 2012-03-28 20:51:05

+1

這裏的問題是重疊區域,我不知道如何實現它。 – temple 2012-03-28 20:54:58

回答

相關問題