2014-09-26 89 views
0

我有一個由兩個框架佈局組成的佈局,我的第一個框架佈局由按鈕組成,另一個框架佈局是空白的,在第一個框架佈局中的按鈕上的點擊事件中,我希望在第二個框架佈局中加載活動佈局? 這是我的XML佈局如何在點擊事件中更改框架佈局中的佈局?

<FrameLayout 
     android:id="@+id/mainframelayout" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     tools:context=".MainActivity" > 

     <LinearLayout 
      android:id="@+id/mainliner" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="horizontal" 
      android:background="#565765"> 
     <FrameLayout 
      android:id="@+id/leftlayout" 
      android:layout_width="wrap_content" 
      android:layout_height="350dp" 
      android:layout_marginTop="30dp" 
      android:background="#321324"> 
      <LinearLayout 
       android:id="@+id/liner" 
       android:layout_width="wrap_content" 
       android:layout_height="fill_parent" 
       android:layout_marginTop="50dp" 
       android:orientation="vertical"> 
      <Button 
       android:id="@+id/btn1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="firstButton" 
       android:text="A"/> 
      <Button 
       android:id="@+id/btn5" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="fifthButton" 
       android:text="B"/> 
      <Button 
       android:id="@+id/btn2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="secondButton" 
       android:text="C"/> 
      <Button 
       android:id="@+id/btn3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="thirdButton"   
       android:text="D"/>   
      <Button 
       android:id="@+id/btn4" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:onClick="fourthButton" 
       android:text="E"/> 
      </LinearLayout>     
     </FrameLayout> 
     <FrameLayout 
      android:id="@+id/rightframe" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="#565765"> 

     </FrameLayout> 
     </LinearLayout> 
    </FrameLayout> 
+0

Layoyt.setvisable(visiable) – 2014-09-26 05:02:43

+0

與ID發佈你的XML佈局代碼 – raj 2014-09-26 05:09:05

+0

從我的按鈕的FrameLayout - 「@ + ID/leftlayout」,我想用ID來更新我的FrameLayout - 「@ + ID/rightframe」。 – 2014-09-26 11:44:12

回答

1
This was the Finalized Solution to my problem. 
On the click event of my button i Just have to set the Visibility of the Desired framelayout to be visible. 

/////////////////////////// The XML LAYOUT////////////////////////////////////////// 


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" > 
    <LinearLayout 
     android:id="@+id/mainliner" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="horizontal" 
     android:layout_below="@+id/relative" 
     android:background="#454565"> 
    <FrameLayout 
     android:id="@+id/leftlayout" 
     android:layout_width="50dp" 
     android:layout_height="300dp" 
     android:layout_marginTop="50dp"> 
     <LinearLayout 
      android:id="@+id/liner" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_marginTop="10dp" 
      android:background="#FF9B00" 
      android:orientation="vertical"> 
     <Button 
      android:id="@+id/btn1" 
      android:layout_marginTop="20dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="firstButton" 
      android:textColor="#000000" 
      android:padding="1dp" 
      android:background="@drawable/roundbtn" 
      android:text="A"/> 
     <Button 
      android:id="@+id/btn2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="secondButton" 
      android:textColor="#000000" 
      android:padding="1dp" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/roundbtn" 
      android:text="B"/> 
     <Button 
      android:id="@+id/btn3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:onClick="thirdButton"   
      android:textColor="#000000" 
      android:layout_marginTop="5dp" 
      android:background="@drawable/roundbtn" 
      android:padding="1dp" 
      android:text="C"/>   
     <Button 
      android:id="@+id/btn4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#000000" 
      android:background="@drawable/roundbtn" 
      android:padding="1dp" 
      android:layout_marginTop="5dp" 
      android:onClick="fourthButton" 
      android:text="D"/> 
     <Button 
      android:id="@+id/btn5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#000000" 
      android:background="@drawable/roundbtn" 
      android:layout_marginTop="5dp" 
      android:onClick="fifthButton" 
      android:text="E"/> 
     </LinearLayout>     
    </FrameLayout> 
    <FrameLayout 
     android:id="@+id/rightframeone" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#123139" 
     android:visibility="invisible"> 
     <GridView 
      android:id="@+id/gridView1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="4dp" 
      android:columnWidth="80dp" 
      android:gravity="center" 
      android:numColumns="auto_fit" 
      android:stretchMode="columnWidth" > 
    </GridView> 
    </FrameLayout> 
    <FrameLayout 
     android:id="@+id/rightframetwo" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#121232" 
     android:visibility="invisible"> 
     <ImageView 
      android:id="@+id/imageview" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/aaaimage" 
      /> 
    </FrameLayout> 
    <FrameLayout 
     android:id="@+id/rightframethree" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#454425" 
     android:visibility="invisible"> 
     <ImageView 
      android:id="@+id/imagevieww" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/bstclass" 
      /> 
    </FrameLayout> 
     <FrameLayout 
     android:id="@+id/rightframefour" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#567004" 
     android:visibility="invisible"> 
     <ImageView 
      android:id="@+id/imageviewww" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/bstteam" 
      />  
    </FrameLayout> 
     <FrameLayout 
     android:id="@+id/rightframefive" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#324888" 
     android:visibility="invisible"> 
     <ImageView 
      android:id="@+id/imageviewwww" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:src="@drawable/training" 
      />  
    </FrameLayout> 
    </LinearLayout> 
</RelativeLayout> 


//////////////////The Method to the triggered in the Class on the click event//////////////////// 

This the functionality we need to do on our button 

    public void firstButton(View view) 
    { 
     frmtwo.setVisibility(View.INVISIBLE); 
     frmtwo.setVisibility(View.GONE); 
     frmthree.setVisibility(View.INVISIBLE); 
     frmthree.setVisibility(View.GONE); 
     frmfour.setVisibility(View.INVISIBLE); 
     frmfour.setVisibility(View.GONE); 
     frmfiv.setVisibility(View.INVISIBLE); 
     frmfiv.setVisibility(View.GONE); 
     frmone.setVisibility(View.VISIBLE); 

    } 
-1

你必須使用片段。

FragmentManager fragmentManager = getFragmentManager(); 
FragmentTransaction fragmentTransaction = fragmentManager 
         .beginTransaction(); 
CalculatorTwo calculator = new CalculatorTwo(); 
fragmentTransaction.setCustomAnimations(R.anim.slide_top, 
         R.anim.slide_down); 
fragmentTransaction.add(R.id.content_first, calculator); 
ragmentTransaction.commit(); 
+0

用於onclick事件的按鈕 – 2014-09-26 05:14:36

+0

,但應該在button的onClick事件上做什麼? – 2014-09-29 04:08:32

+0

試試上面的代碼在OnClick事件中的按鈕類必須是fragment – 2014-09-29 04:19:31