gpt4 book ai didi

android - 使用按钮在 Android 上从布局 1 更改为布局 2

转载 作者:行者123 更新时间:2023-11-30 03:44:25 24 4
gpt4 key购买 nike

我有两个布局,我想在单击按钮时在彼此之间进行更改。它们是这样的全屏 View :

<FrameLayout 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"
android:background="#FF0000"
tools:context=".FullscreenActivity" >

我希望它们在单击时在它们之间切换

 <Button
android:id="@+id/green_button"
style="?buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/green" />

我是否应该更改 src/com.example.layout/fullscreenactivity.java onClick() 中的某些内容,或者我可以在何处更改以便发生这种情况?

提前致谢

最佳答案

rb = (Button) findViewById(R.id.green_button);
rb.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
setContentView(R.layout.OtherLayout);
// now in order to use other layout button, image or any child function you have to declare it under the setContentView(R.layout.OtherLayout);

}
});

请接受答案:)

关于android - 使用按钮在 Android 上从布局 1 更改为布局 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15228386/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com