2017-01-03 14 views
1

Ich muss scrollbare Registerkarten am oberen Rand meiner Anwendung erstellen. Der Tabhost scheint in Ordnung zu sein, aber ich brauche keine Fragmentanzeigen (wie im Bild zu sehen), ich brauche nur Tabs, die einen Clicklistener haben.Tabs ohne Fragment zeigt

Ich brauche nur Tabs wie Tasten, und sie müssen in der Lage sein, horizontal gescrollt und gedrückt werden. Irgendwelche Ideen wie oder ob das gemacht werden kann?

enter image description here

Antwort

2

Verwenden HorizontalScrollView dieses

achive Below I-Code-Snippet bin Bereitstellung, ändern Sie Ihre Forderung nach.

<?xml version="1.0" encoding="utf-8"?> 
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical"> 
      <ImageButton 
       android:id="@+id/imageButton1" 
       android:layout_width="wrap_content" 
       android:layout_height="100dp" 
       android:src="@drawable/pic7" 
       android:text="image1" /> 
      <TextView 
       android:id="@+id/text" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:text="Textview1" /> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:orientation="vertical" 
      android:layout_height="fill_parent"> 
      <ImageButton 
       android:text="image2" 
       android:id="@+id/imageButton2" 
       android:layout_width="wrap_content" 
       android:layout_height="100dp" 
       android:src="@drawable/pic2" /> 
      <TextView 
       android:id="@+id/text" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:text="Textview2" /> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:orientation="vertical" 
      android:layout_height="fill_parent"> 
      <ImageButton 
       android:text="image3" 
       android:id="@+id/imageButton3" 
       android:layout_width="wrap_content" 
       android:layout_height="100dp" 
       android:src="@drawable/pic7" /> 
      <TextView 
       android:id="@+id/text" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:text="Textview3" /> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:orientation="vertical" 
      android:layout_height="fill_parent"> 
      <ImageButton 
       android:text="image4" 
       android:id="@+id/imageButton4" 
       android:layout_width="wrap_content" 
       android:layout_height="100dp" 
       android:src="@drawable/pic5" /> 
      <TextView 
       android:id="@+id/text4" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:text="Textview4" /> 
     </LinearLayout> 
    </LinearLayout> 
</HorizontalScrollView> 
+0

Also mit diesem XML muss ich meine eigenen Schaltflächen für die Registerkarten erstellen? –

+0

@DRCodeTutorial Sie müssen es so entwerfen, wird es aussehen wie tablayout und wird Tasten haben, und dann noraml Weg inilitaize Tasten und geben Sie Klick Aktion zu diesen Tasten – Mrinmoy

+0

Vielen Dank, das funktioniert gut, perfekt für das, was ich brauche :) –

0

Dies kann durch Verwendung TabLayout und stellen seine tabmode zu scrollable tabs

schaffen eine neue Aktivität mit ViewPager Tabs und in TabLayout gesetzt seinen Modus Rollbare achived werden.

<android.support.design.widget.TabLayout xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/tabs" 
app:tabMode="scrollable" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" /> 

Verweisen Sie auf diese Seite, um Tab-Aktivitäten mit Viewgager zu erstellen. TabLayout with viewPager