如何在单击事件上更改框架布局中的布局? [英] how to change the layout in frame layout on the click event?

查看:24
本文介绍了如何在单击事件上更改框架布局中的布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个由两个框架布局组成的布局,我的第一个框架布局由按钮组成,另一个框架布局是空白的,在第一个框架布局中的按钮上单击事件时,我希望在第二个框架中加载活动布局布局?这是我的 XML 布局

i have an layout consisting of two frame layout, my first Frame layout consist of the buttons,and another Frame layout is blank ,on click event on the button in first frame layout i wish to load the Activity layout in the second Frame layout? This is my XML LAYOUT

    <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>

推荐答案

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);

    }

这篇关于如何在单击事件上更改框架布局中的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆