2012-03-28 11 views
0

Wie man diese Art von Tab in Android [http://i.stack.imgur.com/rIbUX.png]Wie benutzerdefinierte Tab-Host in Android

nur erwähnen, dass finden Sie im Überlappungsbereich implementieren, wenn Sie klicken auf die Registerkarte, die Überlappung wurde geändert.

hier ist eine chinesische Version Beispiel, in dem ich denke, das ist, was ich haben möchte, aber sie bieten nicht den vollständigen Code, und ich habe keine Ahnung, wie man auf dieses Projekt geht.

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

Ich bin derzeit mit Android 3.2 und ICS 4+ dieses Projekt umzusetzen, so willkommen, wenn das möglich ist mit Framgment zu implementieren competible.


Endlich habe ich die Lösung selbst gemacht. Ich lasse nur die native Tab-Host-Implementierung, meine eigene.

hier ist der Screenshot: [http://i.stack.imgur.com/1mXLZ.png]

hier ist der Code Aktivität:

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(); 
     } 
    }); 

} 
} 

hier ist die Layoutdatei ich benutze (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

Hier haben Sie ein schönes Beispiel für die Implementierung von benutzerdefinierten TabHost: http://www.anddev.org/code-snippets-for-android-f33/iphone-tabs-for-android -t14678.html – Emran

+1

das Problem hier der Überlappungsbereich, in dem ich nicht weiß, wie man es implementiert. – temple

Antwort

Verwandte Themen