gpt4 book ai didi

android - 如何使按钮重定向到另一个 XML 布局

转载 作者:行者123 更新时间:2023-11-29 18:03:17 26 4
gpt4 key购买 nike

我在 xml (res/layout/activity_home.xml) 中制作一个按钮,如下所示:

<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=".HomeActivity" >
<ImageView
android:id="@+id/imageView1"
android:src="@drawable/schkopwide"
android:contentDescription="@string/HTI"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="78dp"
android:onclick="Intent i = new Intent(activity_store.xml);
startActivity(i);"
android:text="@string/HTI" />
</RelativeLayout>

那么我应该在这个 xml 中添加什么让它重定向到另一个 xml 页面(res/layout/activity_store.xml)?

谢谢

最佳答案

如果你想在同一个 Activity 中显示两个不同的布局,那么 ViewSwitcher 是最好的布局。

您可以在 ViewSwitcher 中添加多个布局。并使用 viewswitcher.next(); 函数替换它们。

<ViewSwitcher

android:id="@+id/viewswitcher"
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<!-- Add Two View’s Here -- >

</ViewSwitcher>

您可以引用此链接:http://abhiandroid.com/ui/viewswitcher

关于android - 如何使按钮重定向到另一个 XML 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14685790/

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