2017-03-26 2 views
-1

APP가 있고 하나의 활동에 TabHost 컨트롤에 두 개의 탭이 포함되어 있지만 정상적으로 작동했지만 두 번째 탭만 작동합니다. 두 탭 모두에서 내용을 볼 수 있지만 두 번째 항목 만 스크롤하고 선택할 수 있습니다. 첫 번째 탭을 스크롤하려고하면이 하나는 움직이지 않지만 스크롤 막대가 움직이는 것을 볼 수 있으며 두 번째 탭이 실제로 움직이고 있으므로 두 번째 탭으로 돌아 가면 다른 위치에있게됩니다. 내가 첫 번째 탭을 선택하려고하면 아무 일도 일어나지 않습니다.Android. 두 개의 탭이 있으며 하나만 응답합니다.

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

이런 일이 왜 어떤 생각 다음은 레이아웃과 코드는? 감사.

답변

0

마지막으로 나는 FrameLayout 외부에 ScrollView를 배치하는 대답을 얻었다.

<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> 
관련 문제