Android。我有两个标签,只有一个对触摸有反应

Android. I have two tabs and only one responds to touch

我有一个 APP,其中一个 activity 在 TabHost 控件中包含两个选项卡,它工作正常,但现在只有第二个选项卡有效。我在两个选项卡中都看到了内容,但我只能在第二个选项卡上滚动和 select 一个项目。如果我尝试滚动第一个选项卡,这个选项卡不会移动,但我看到滚动条在移动,实际上第二个选项卡在移动,所以如果我 return 到第二个选项卡现在处于不同的位置。如果我尝试在第一个选项卡上 select 和 ítem 没有任何反应。这是布局和代码:

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

知道为什么会这样吗?谢谢

最后我得到了将 ScrollView 放在 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>