2012-10-22 50 views
2

我使用FrameLayout像一堆視圖使用onClick事件進行更改,但它不工作。FrameLayout setVisibility()不起作用

FrameLayout frameEvento顯示正常,但當我點擊它時調用我的方法,但 不要更改幀的可見性。

< ----片段代碼------->

<code> 
View V = inflater.inflate(R.layout.home_fragment_layout, container, false); 

LinearLayout ll = (LinearLayout) V.findViewById(R.id.homeLinearLayout); 

FrameLayout f = (FrameLayout) V.findViewById(R.id.frameEvento); 
f.setVisibility(View.GONE); 
f.requestLayout(); 

FrameLayout f1 = (FrameLayout) V.findViewById(R.id.frameEventoSecundario); 
f1.setVisibility(View.VISIBLE); 
f1.requestLayout(); 

ll.invalidate(); 

< ----佈局代碼------->

<code> 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/homeLinearLayout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#FFFFFF" 
android:orientation="vertical" > 



<FrameLayout 
    android:id="@+id/frameEvento" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginTop="5dp" 
    > 

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

    <ImageView 
     android:id="@+id/homeBotaoEventoPricipal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" 
     android:src="@drawable/bt_hsm" 
     android:scaleType="fitCenter" 
     android:onClick="goEventoPrincipal" 
     android:contentDescription="@string/expomanagement" 
     android:text="" /> 

    <ImageView 
     android:id="@+id/homeBotaoEventoSecundario" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" 
     android:layout_marginTop="5dp" 
     android:scaleType="fitCenter" 
     android:src="@drawable/bt_bdw" 
     android:onClick="goEventoSecundario" 
     android:contentDescription="@string/brasil_design_week" 
     android:text="" /> 
    </LinearLayout> 
</FrameLayout> 

<FrameLayout 
android:id="@+id/frameEventoSecundario" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:layout_marginLeft="0dp" 
    android:layout_marginRight="0dp" 
    android:layout_marginTop="5dp" 
    android:visibility="gone" 
> 

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

<ImageView 
     android:id="@+id/homeHeader" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:src="@drawable/bg_header_bdw" 
     android:scaleType="fitCenter" 
     android:contentDescription="@string/brasil_design_week" 
     android:text="" /> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="276dp" 
    android:layout_height="75dp" 
    android:layout_marginLeft="20dp" 
    android:text="UHUHUH" 
    android:textSize="6pt" 
    android:textStyle="bold" /> 

    <TextView 
    android:id="@+id/textView2" 
    android:layout_width="276dp" 
    android:layout_height="75dp" 
    android:layout_marginLeft="20dp" 
    android:text="PLOKO" 
    android:textSize="5pt" 
    /> 

      <TextView 
    android:id="@+id/textView3" 
    android:layout_width="276dp" 
    android:layout_height="75dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginTop="20dp" 
    android:text="FDSAF" 
    android:textSize="5pt" 
    /> 

      <TextView 
    android:id="@+id/textView3" 
    android:layout_width="276dp" 
    android:layout_height="75dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginTop="20dp" 
    android:text="QWERT" 
    android:textSize="5pt" 
    /> 

          <TextView 
    android:id="@+id/textView3" 
    android:layout_width="276dp" 
    android:layout_height="75dp" 
    android:layout_marginLeft="20dp" 
    android:layout_marginTop="20dp" 
    android:text="ABCD" 
    android:textSize="5pt" 
    /> 
    </LinearLayout> 
</FrameLayout> 
</LinearLayout></code> 
+0

它看起來像是不更新視圖..即使removeAllViews不起作用 – Alexandre

回答

0

它會更好,如果你打電話findViewbyId()而不是V

FrameLayout f = (FrameLayout) ll.findViewById(R.id.frameEvento); 

你不要需要調用請求佈局,因爲invalidate會重繪您的視圖。順便說一下,「容器」是指什麼?

+0

我會嘗試你的建議,容器是一個ViewGroup:ViewGroup容器; – Alexandre

+0

我刪除了請求調用,現在從linearlayout獲取框架,但它仍然沒有隱藏FrameLayout「frameEvento」 – Alexandre

+0

您在哪裏以及如何獲取容器? –

相關問題