我怎样才能改变包括的XML布局关于java code另一个布局? [英] How can i change included xml layout to another layout on java code?

查看:106
本文介绍了我怎样才能改变包括的XML布局关于java code另一个布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。我开发Android应用程序。

我包含第二布局的第一个布局是这样的:

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>

< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =300dp
    机器人:layout_height =match_parent
    机器人:layout_gravity =clip_horizo​​ntal
    机器人:layout_alignParentLeft =真
    机器人:ID =@ + ID / rlMenu
    >

    <按钮
        机器人:ID =@ + ID / bMusteriler
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文本=Musteriler
        机器人:TEXTSIZE =45dp
        机器人:layout_alignParentLeft =真
         />

< / RelativeLayout的>

< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =match_parent
    机器人:layout_toRightOf =@ ID / rlEkranlar
     >

    <包括
        机器人:ID =@ + ID / include1
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        布局=@布局/ ikinci/>

< / RelativeLayout的>
< / RelativeLayout的>
 

问题是我如何改变包括布局时,单击按钮(关于java code)?

对不起,我的英语。 谢谢你。

<= DIV级h2_lin>的解决方案

建议 ViewFlipper RelativeLayout的包括语句。尝试是这样的:

 &LT; ViewFlipper的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID / VF
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT&GT;

    &LT;包括机器人:ID =@ + ID / include1布局=@布局/ ikinci/&GT;
    &LT;包括机器人:ID =@ + ID /图布局=@布局/ third_layout/&GT;

&LT; / ViewFlipper&GT;
 

访问ViewFlipper如下。 首先第一个布局是输出:

  ViewFlipper VF =(ViewFlipper)findViewById(R.id.vf);
 

有关按钮onClickListener:

  button.setOnClickListener(新View.OnClickListener(){

            @覆盖
            公共无效的onClick(视图v){
                // TODO自动生成方法存根
                vf.setDisplayedChild(1);
            }
        });
 

i have a problem. I develop android application.

I included second layout to first layout like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:layout_gravity="clip_horizontal"
    android:layout_alignParentLeft="true" 
    android:id="@+id/rlMenu"
    >

    <Button
        android:id="@+id/bMusteriler"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Musteriler"
        android:textSize="45dp"
        android:layout_alignParentLeft="true"
         />

</RelativeLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_toRightOf="@id/rlEkranlar"
     >

    <include
        android:id="@+id/include1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        layout="@layout/ikinci" />

</RelativeLayout>
</RelativeLayout>

Problem is how can i change included layout when clicked a button(on java code) ?

Sorry for my English. Thanks.

解决方案

I suggest ViewFlipper inside RelativeLayout of your include statements. Try like this:

<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/vf"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <include android:id="@+id/include1" layout="@layout/ikinci" />
    <include android:id="@+id/map" layout="@layout/third_layout" />

</ViewFlipper>

Access ViewFlipper as below. Initially first layout is output:

ViewFlipper vf = (ViewFlipper)findViewById(R.id.vf);

For Button onClickListener:

button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                vf.setDisplayedChild(1);
            }
        });

这篇关于我怎样才能改变包括的XML布局关于java code另一个布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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