Android如何设置选项选择和查看屏幕
我是android新手,我正在尝试创建一个应用程序来帮助用户进行训练。我知道这个问题相当大,可能有点模糊,所以我会尽我所能解释它,希望我能得到一个我可以使用的答案 问题是,我一直在为如何设置不同的活动以及它们需要如何相互交互而挣扎。这就是它看起来的样子:Android如何设置选项选择和查看屏幕,android,Android,我是android新手,我正在尝试创建一个应用程序来帮助用户进行训练。我知道这个问题相当大,可能有点模糊,所以我会尽我所能解释它,希望我能得到一个我可以使用的答案 问题是,我一直在为如何设置不同的活动以及它们需要如何相互交互而挣扎。这就是它看起来的样子: _________ _________ _________ | | | | | | | | |
_________ _________ _________
| | | | | |
| | | | | |
| | | | | |
| 1 | ---> | 2 | --> | 3 |
| | | | | |
| | | | | |
|_________| |_________| |_________|
menu options select options shown
但是,在用户选择其选项后,应为:
_________ _________
| | | |
| | | |
| | | |
| 1 | ---> | 3 |
| | | |
| | | |
|_________| |_________|
menu options shown
用户还应该能够从屏幕3返回屏幕2以更改其选项。我只是不知道最好的方法是什么。特别是与后退按钮的互动
最好有3个活动,并尽量将它们联系在一起,我能做的最好,还是应该有2个具有可变布局的活动?也许用碎片?或者有更好的方法吗?您需要使用SharedReference。 在Activity2中,您需要获取SharedReferenceString,如果它设置为值,您只需启动activity3,否则让用户选择并设置SharedReferenceString。 在activity3中,您可以删除该SharedReferenceString,因此当您输入activity2时,它将不再被设置,您可以让用户重新选择。
以下是您需要使用SharedReference的。 在Activity2中,您需要获取SharedReferenceString,如果它设置为值,您只需启动activity3,否则让用户选择并设置SharedReferenceString。 在activity3中,您可以删除该SharedReferenceString,因此当您输入activity2时,它将不再被设置,您可以让用户重新选择。 这是我的建议
您可以使用
NavigationView
和DrawerLayout
的Activity
,它提供菜单功能,并具有一个FrameLayout
容器,您可以在其中根据选项加载片段。您的活动布局文件可以如下所示:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".home.HomeActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:itemBackground="@color/white"
app:itemTextAppearance="?attr/textAppearanceListItem"
app:menu="@menu/drawer" />
您可以使用
导航视图和抽屉布局来进行活动
,它提供菜单功能,并具有一个框架布局
容器,您可以在其中根据选项加载片段。您的活动布局文件可以如下所示:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".home.HomeActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:itemBackground="@color/white"
app:itemTextAppearance="?attr/textAppearanceListItem"
app:menu="@menu/drawer" />
为什么我需要抽屉布局?我不能在现有布局中使用框架布局吗?抽屉布局用于滑动菜单抽屉为什么需要抽屉布局?我不能在现有布局中使用框架布局吗?抽屉布局用于滑动菜单抽屉