0

팽창 된 레이아웃에서 구성 요소를 숨기는 방법을 아는 사람이 있습니까? 나는 다음과 같은 코드가 있습니다팽창 된 레이아웃에서 xml 구성 요소 숨기기

View tabLayout = LayoutInflater.from(this).inflate(R.layout.tab_layout, null); 
FrameLayout profile_tab_selected_indicator = 
     (FrameLayout)tabLayout.findViewById(R.id.profile_tab_selected_indicator); 

을 때 내가 사용하여 숨길려고 : 그것은 작동하지 않습니다

profile_tab_selected_indicator.setVisibility(View.GONE); 

. 내가 뭔가를 놓치고있는 것처럼 보이거나 부풀린 레이아웃에서 xml 구성 요소를 숨길 수 없습니다. 또한 LayoutParams을 통해 너비와 높이를 0dp으로 설정하려고 시도했지만 제대로 작동하지 않습니다. 이 같은 onCreate() 이외의 사용자 정의 기능에서

:

다음
public static View tabLayout; 

protected void onCreate(){ 
    //some code here 
buildTabLayout(); 
} 

public void buildTabLayout(){ 
    tabLayout = LayoutInflater.from(this).inflate(R.layout.tab_layout, null); 
} 

내가 여기를 숨기기 위해 노력하고있어 여기에

public void onTabChanged(String tabId) { 
    FrameLayout profile_tab_selected_indicator = (FrameLayout)tabLayout.findViewById(R.id.profile_tab_selected_indicator); 

    profile_tab_selected_indicator.setVisibility(View.GONE); 
} 

가 팽창 레이아웃의 XML 코드의

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/profile_tab_bar_bg" 
    android:gravity="center" 
    android:orientation="vertical" > 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/profile_top_bar_shadow_xml" > 
    </FrameLayout> 

    <ImageView 
     android:id="@+id/iv_tabIcon" 
     android:layout_width="30dp" 
     android:layout_height="30dp" /> 

    <TextView 
     android:id="@+id/tv_tabTitle" 
     style="@style/ProfileTabLabelsStyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="@drawable/profile_tab_label_selector" /> 

    <FrameLayout 
     android:id="@+id/profile_tab_selected_indicator" 
     android:layout_width="match_parent" 
     android:layout_height="2dp" 
     android:background="@color/ProfileTabSelected" > 
    </FrameLayout> 

</LinearLayout> 

편집 :

내 탭 레이아웃에 대한 책임

모든 코드 : 당신은 당신의 코드에서 잘못된 몇 가지를 한 적이

// tabs labels 
    public static String[] tabsTitles = new String[] { "PROFILE", "CAMPAIGNS", 
      "STATISTICS" }; 

    public static View tabLayout; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.vw_profile); 

     // initializing xml components 
     init(); 

     // Tab Layut builder 
     buildTabLayout(); 


    } 
private void buildTabLayout() { 
     // TODO Auto-generated method stub 
     Resources res = getResources(); // Resource object to get Drawables 
     TabHost tabHost = getTabHost(); // The activity TabHost 
     tabHost.setOnTabChangedListener(this); 
     TabHost.TabSpec spec; // Resusable TabSpec for each tab 
     View tabLayout; // tabLayout 
     Intent intent; // Reusable Intent for each tab 

     // PROFILE TAB 
     tabLayout = createTabLayout(this, tabsTitles[0]); 
     intent = new Intent().setClass(this, VieweedsProfileTabActivity.class); 
     spec = tabHost.newTabSpec(tabsTitles[0]).setIndicator(tabLayout) 
       .setContent(intent); 
     tabHost.addTab(spec); 

     // CAMPAIGNS TAB 
     tabLayout = createTabLayout(this, tabsTitles[1]); 
     intent = new Intent() 
       .setClass(this, VieweedsCampaignsTabActivity.class); 
     spec = tabHost.newTabSpec(tabsTitles[1]).setIndicator(tabLayout) 
       .setContent(intent); 
     tabHost.addTab(spec); 

     // STATISTICS TAB 
     tabLayout = createTabLayout(this, tabsTitles[2]); 
     intent = new Intent().setClass(this, 
       VieweedsStatisticsTabActivity.class); 
     spec = tabHost.newTabSpec(tabsTitles[2]).setIndicator(tabLayout) 
       .setContent(intent); 
     tabHost.addTab(spec); 

     tabHost.setCurrentTab(0); 

    } 

    public void onTabChanged(String tabId) { 
     // TODO Auto-generated method stub 
     FrameLayout profile_tab_selected_indicator = (FrameLayout)tabLayout.findViewById(R.id.profile_tab_selected_indicator); 
     FrameLayout campaigns_tab_selected_indicator = (FrameLayout)tabLayout.findViewById(R.id.campaigns_tab_selected_indicator); 

     if (tabId.equals(tabsTitles[0])) { 
      // profile tab 
      Toast.makeText(this, tabId, Toast.LENGTH_LONG).show(); 
      profile_tab_selected_indicator.setVisibility(View.VISIBLE); 
      campaigns_tab_selected_indicator.setVisibility(View.GONE); 
     } else if (tabId.equals(tabsTitles[1])) { 
      // campaigns tab 
      Toast.makeText(this, tabId, Toast.LENGTH_LONG).show(); 
      profile_tab_selected_indicator.setVisibility(View.GONE); 
      campaigns_tab_selected_indicator.setVisibility(View.VISIBLE); 
     } else { 
      Toast.makeText(this, tabId, Toast.LENGTH_LONG).show(); 
      // statistics tab 

     } 
    } 

    // creating tab layout for each tab 
    public static View createTabLayout(Context c, String tabTitleText){ 
     tabLayout = LayoutInflater.from(c).inflate(R.layout.tab_layout, null); 
     TextView tabTitle = (TextView)tabLayout.findViewById(R.id.tv_tabTitle); 
     tabTitle.setTypeface(arial); 
     ImageView tabIcon = (ImageView)tabLayout.findViewById(R.id.iv_tabIcon); 
     tabTitle.setText(tabTitleText); 

     //assigning tab icons for each tab 
     if(tabTitleText.equals(tabsTitles[0])){ 
      //profile tab 
      tabIcon.setImageResource(R.drawable.profile_tab_bar_profile_tab_icon); 
     }else if(tabTitleText.equals(tabsTitles[1])){ 
      //campaigns tab 
      tabIcon.setImageResource(R.drawable.profile_tab_bar_campaigns_tab_icon); 
     }else{ 
      //statistics tab 
      tabIcon.setImageResource(R.drawable.profile_tab_bar_statistics_tab_icon); 
     } 

     return tabLayout; 
    } 
+0

제공하십시오 당신이 추가 곳 귀하의 코드에서 tabLayout? –

+0

레이아웃의 XML을 제공해야합니다. 언뜻보기에는 코드가 괜찮습니다 –

+0

XML 코드로 질문을 업데이트했습니다. 고맙습니다! –

답변

0

. 나는 당신이 왜 tabLayout을 클래스의 필드를 만들기로 선택했는지 알지 못하지만 이것을 수행함으로써 tabLayout은 설정 한 마지막 탭 인디케이터 (STATISTICS 탭의 것)를 가리킬 것입니다. tabLayout이 마지막 탭만 가리키기 때문에 onTabChanged 콜백에서 아무 것도 나타나지 않습니다 (마지막 탭에서는 아무 것도하지 않기 때문에).

나는 당신의 onTabChanged 방법을 변경하고 당신이 올바른 위치에 그 FrameLayout 검색하는 확인하기 위해 getChildTabViewAt와 직접 탭 뷰를 검색 할 수 권합니다 :

public void onTabChanged(String tabId) { 
     // the first tab view 
     View tab1 = getTabWidget().getChildTabViewAt(0); 
     FrameLayout profile_tab_selected_indicator = (FrameLayout)tab1.findViewById(R.id.profile_tab_selected_indicator); 
     // the second tab view 
     View tab2 = getTabWidget().getChildTabViewAt(1); 
     // where does this come from?!?! it is in the second tab?!?! 
     FrameLayout campaigns_tab_selected_indicator = (FrameLayout)tab2.findViewById(R.id.campaigns_tab_selected_indicator); 
     // the third tab view 
     View tab3 = getTabWidget().getChildTabViewAt(2);    

     if (tabId.equals(tabsTitles[0])) { 
      // profile tab 
      Toast.makeText(this, tabId, Toast.LENGTH_LONG).show();      
      profile_tab_selected_indicator.setVisibility(View.VISIBLE); 
      campaigns_tab_selected_indicator.setVisibility(View.GONE); 
     } else if (tabId.equals(tabsTitles[1])) { 
      // campaigns tab 
      Toast.makeText(this, tabId, Toast.LENGTH_LONG).show(); 
      profile_tab_selected_indicator.setVisibility(View.GONE); 
      campaigns_tab_selected_indicator.setVisibility(View.VISIBLE); 
     } else { 
      Toast.makeText(this, tabId, Toast.LENGTH_LONG).show(); 
      // statistics tab 

     } 
    }