我有一个布局由两个框架布局,我的第一个框架布局包括按钮,另一个框架布局是空白的,就在第一帧布局按钮单击事件我想加载活动布局在第二帧布局? 这是我的XML布局
<的FrameLayout
机器人:ID =@ + ID / mainframelayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=MainActivity。>
<的LinearLayout
机器人:ID =@ + ID / mainliner
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=横向
机器人:后台=#565765>
<的FrameLayout
机器人:ID =@ + ID / leftlayout
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =350dp
机器人:layout_marginTop =30dp
机器人:后台=#321324>
<的LinearLayout
机器人:ID =@ + ID /衬垫
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:layout_marginTop =50dp
机器人:方向=垂直>
<按钮
机器人:ID =@ + ID / BTN1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:的onClick =firstButton
机器人:文本=A/>
<按钮
机器人:ID =@ + ID / btn5
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:的onClick =fifthButton
机器人:文本=B/>
<按钮
机器人:ID =@ + ID / BTN2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:的onClick =secondButton
机器人:文本=C/>
<按钮
机器人:ID =@ + ID / btn3
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:的onClick =thirdButton
机器人:文本=D/>
<按钮
机器人:ID =@ + ID / btn4
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:的onClick =fourthButton
机器人:文本=E/>
< / LinearLayout中>
< /的FrameLayout>
<的FrameLayout
机器人:ID =@ + ID / rightframe
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:后台=#565765>
< /的FrameLayout>
< / LinearLayout中>
< /的FrameLayout>
解决方案
这是最后确定的解决我的问题。
在我的按钮的单击事件我只需要设置所需的FrameLayout的可见性可见。
///////////////////////////的XML布局//////////////////// //////////////////////
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=MainActivity。>
<的LinearLayout
机器人:ID =@ + ID / mainliner
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=横向
机器人:layout_below =@ + ID /相对
机器人:后台=#454565>
<的FrameLayout
机器人:ID =@ + ID / leftlayout
机器人:layout_width =50dp
机器人:layout_height =300dp
机器人:layout_marginTop =50dp>
<的LinearLayout
机器人:ID =@ + ID /衬垫
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =FILL_PARENT
机器人:layout_marginTop =10dp
机器人:后台=#FF9B00
机器人:方向=垂直>
<按钮
机器人:ID =@ + ID / BTN1
机器人:layout_marginTop =20dp
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:的onClick =firstButton
机器人:文字颜色=#000000
机器人:填充=1DP
机器人:背景=@可绘制/ roundbtn
机器人:文本=A/>
<按钮
机器人:ID =@ + ID / BTN2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:的onClick =secondButton
机器人:文字颜色=#000000
机器人:填充=1DP
机器人:layout_marginTop =5DP
机器人:背景=@可绘制/ roundbtn
机器人:文本=B/>
<按钮
机器人:ID =@ + ID / btn3
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:的onClick =thirdButton
机器人:文字颜色=#000000
机器人:layout_marginTop =5DP
机器人:背景=@可绘制/ roundbtn
机器人:填充=1DP
机器人:文本=C/>
<按钮
机器人:ID =@ + ID / btn4
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字颜色=#000000
机器人:背景=@可绘制/ roundbtn
机器人:填充=1DP
机器人:layout_marginTop =5DP
机器人:的onClick =fourthButton
机器人:文本=D/>
<按钮
机器人:ID =@ + ID / btn5
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字颜色=#000000
机器人:背景=@可绘制/ roundbtn
机器人:layout_marginTop =5DP
机器人:的onClick =fifthButton
机器人:文本=E/>
< / LinearLayout中>
< /的FrameLayout>
<的FrameLayout
机器人:ID =@ + ID / rightframeone
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:后台=#123139
机器人:能见度=隐形>
< GridView控件
机器人:ID =@ + ID / gridView1
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_margin =4DP
机器人:columnWidth中=80dp
机器人:重力=中心
机器人:为numColumns =auto_fit
机器人:stretchMode =columnWidth中>
< / GridView的>
< /的FrameLayout>
<的FrameLayout
机器人:ID =@ + ID / rightframetwo
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:后台=#121232
机器人:能见度=隐形>
< ImageView的
机器人:ID =@ + ID / ImageView的
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:SRC =@可绘制/ aaaimage
/>
< /的FrameLayout>
<的FrameLayout
机器人:ID =@ + ID / rightframethree
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:后台=#454425
机器人:能见度=隐形>
< ImageView的
机器人:ID =@ + ID / imagevieww
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:SRC =@可绘制/ bstclass
/>
< /的FrameLayout>
<的FrameLayout
机器人:ID =@ + ID / rightframefour
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:后台=#567004
机器人:能见度=隐形>
< ImageView的
机器人:ID =@ + ID / imageviewww
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:SRC =@可绘制/ bstteam
/>
< /的FrameLayout>
<的FrameLayout
机器人:ID =@ + ID / rightframefive
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:后台=#324888
机器人:能见度=隐形>
< ImageView的
机器人:ID =@ + ID / imageviewwww
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:SRC =@可绘制/培训
/>
< /的FrameLayout>
< / LinearLayout中>
< / RelativeLayout的>
//////////////////的方法在触发类的单击事件////////////////////
这个功能,我们需要做我们的按钮
公共无效firstButton(查看视图)
{
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);
}
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);
}
上一篇:为什么在设置参数的片段应用程序崩溃应用程序、片段、参数
下一篇:C#/。NET 4.0创建自定义configElements和configCollection自定义、NET、configElements、configCollection