2017-03-26 2 views
-1

J'ai une application et une activité contient deux onglets dans un contrôle TabHost, cela a bien fonctionné, mais maintenant seul le deuxième onglet fonctionne. Je vois le contenu dans les deux onglets mais je ne peux que faire défiler et sélectionner un élément sur le second. Si j'essaie de faire défiler le premier onglet, celui-ci ne bouge pas, mais je vois la barre de défilement se déplacer et en fait la deuxième languette bouge, donc si je retourne au second onglet, c'est maintenant dans une position différente. Si j'essaie de sélectionner et d'écrire sur le premier onglet rien ne se passe. Voici la mise en page et le code:Android. J'ai deux onglets et un seul répond à toucher

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_tab_mesas" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".TabMesasActivity"> 

<TabHost 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:id="@+id/tab_host"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
      <ScrollView 
       android:id="@+id/scrl_tab1" 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" > 
       <RelativeLayout 
        android:id="@+id/tab1" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 

       </RelativeLayout> 
      </ScrollView> 

      <ScrollView 
       android:id="@+id/scrl_tab2" 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" > 
       <RelativeLayout 
        android:id="@+id/tab2" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
       </RelativeLayout> 
      </ScrollView> 
     </FrameLayout> 
    </LinearLayout> 
</TabHost> 

package xxxxxx; 

import android.content.Intent; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.widget.RelativeLayout; 
import android.widget.TabHost; 

import java.util.List; 

public class TabMesasActivity extends AppCompatActivity { 
    TabHost tabHost; 
    List<String> lstMesasSala; 
    List<String> lstMesasTerraza; 
    clsBBDD bd = new clsBBDD(); 
    RelativeLayout layoutSala; 
    RelativeLayout layoutTerraza; 
    TabHost.TabSpec spec; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_tab_mesas); 
    tabHost = (TabHost)findViewById(R.id.tab_host); 
    //Botones Mesas 
    layoutSala = (RelativeLayout) findViewById(R.id.tab1); 
    layoutTerraza = (RelativeLayout) findViewById(R.id.tab2); 
    tabHost.setup(); 

    //Tab 1 
    spec = tabHost.newTabSpec("SALON"); 
    spec.setContent(R.id.tab1); 
    spec.setIndicator("SALON"); 
    tabHost.addTab(spec); 

    //Tab 2 
    spec = tabHost.newTabSpec("TERRAZA"); 
    spec.setContent(R.id.tab2); 
    spec.setIndicator("TERRAZA"); 
    tabHost.addTab(spec); 

    if (savedInstanceState != null) 
     tabHost.setCurrentTab(savedInstanceState.getInt("tabId")); 

    lstMesasSala = bd.SelectMesasSalaDB(); 
    lstMesasTerraza = bd.SelectMesasTerrazaDB(); 

    clsSoporte.AñadirBotones(lstMesasSala, layoutSala, getWindow(), TabMesasActivity.this, TicketActivity.class); 
    clsSoporte.AñadirBotones(lstMesasTerraza, layoutTerraza, getWindow(), TabMesasActivity.this, TicketActivity.class); 
} 

public void onSaveInstanceState(Bundle savedState) { 
    super.onSaveInstanceState(savedState); 
    //Guardar tab id 
    int intTabId = tabHost.getCurrentTab(); 
    savedState.putInt("tabId", intTabId); 

} 

public void onBackPressed(){ 
    Intent i = new Intent(TabMesasActivity.this, MainActivity.class); 
    startActivity(i); 
    finish(); 
} 
} 

Toute idée pourquoi est-ce qui se passe? Merci.

Répondre

0

Enfin, j'ai obtenu la réponse en mettant le ScrollView en dehors de la FrameLayout.

<ScrollView 
    android:id="@+id/scrl_tab1" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
       <RelativeLayout 
        android:id="@+id/tab1" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
       </RelativeLayout> 
       <RelativeLayout 
        android:id="@+id/tab2" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical"> 
       </RelativeLayout> 
      </FrameLayout> 
     </ScrollView>