活动建议和最佳实践中的Android UI导航
我卡住了! 我正在开发我的第一个Android应用程序,所以我被认为是一个初学者。我有一些编程背景,所以我设法自己解决了第一个问题。但现在我已经到了一个不知道如何解决几个问题的地步。所以请与我分享你永恒的智慧 我正在开发一个游戏。我希望菜单位于虚拟电话中。下面的图片最能描述我想要实现的目标。别被这些话弄糊涂了,我来自德国。 Einstellungen=首选项 当我按下菜单按钮时,会调用一个片段。目前,片段的布局包含相对布局,android:background设置为整个图像。我想要实现的是,电话框始终保持不变,只有视图(红色)会改变。使用向上和向下按钮,我希望能够将选择器(蓝色)移动到不同的菜单项。如果我按OK(黄色),则所选项目称为e新视图,在红色区域中从右侧滑动。希望这是清楚的 因此,我的问题是:活动建议和最佳实践中的Android UI导航,android,android-fragments,view,Android,Android Fragments,View,我卡住了! 我正在开发我的第一个Android应用程序,所以我被认为是一个初学者。我有一些编程背景,所以我设法自己解决了第一个问题。但现在我已经到了一个不知道如何解决几个问题的地步。所以请与我分享你永恒的智慧 我正在开发一个游戏。我希望菜单位于虚拟电话中。下面的图片最能描述我想要实现的目标。别被这些话弄糊涂了,我来自德国。 Einstellungen=首选项 当我按下菜单按钮时,会调用一个片段。目前,片段的布局包含相对布局,android:background设置为整个图像。我想要实现的是,电
来自德国的问候(如果我的英语不完美,我很抱歉) 你一下子问了很多问题,所以我很难给出一个明确的答案。我只想向你们解释一下我将如何构建这样一个屏幕: 1)布局: 您可以简单地使用RelativeLayout构建布局:
<?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">
<FrameLayout
android:id="@+id/flFragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginTop="64dp"
android:layout_marginLeft="64dp"
android:layout_marginRight="64dp"
android:layout_marginBottom="128dp"
android:background="#ff0000"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/btnDown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="15dp"
android:text="@string/fragment_main_button_down_text"/>
<Button
android:id="@+id/btnUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/btnDown"
android:layout_centerHorizontal="true"
android:text="@string/fragment_main_button_up_text"/>
<Button
android:id="@+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/btnDown"
android:layout_alignParentBottom="true"
android:text="@string/fragment_main_button_close_text"/>
<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/btnDown"
android:layout_alignParentBottom="true"
android:text="@string/fragment_main_button_ok_text"/>
</RelativeLayout>
</RelativeLayout>
下面是结果,在我的示例应用程序中,每次按OK时都会执行FragmentTransaction:
这听起来像至少3个独立的问题。我知道这有点重:(但我想所有的问题都应该放在一起。我不需要解决方案,我只想指出正确的方向。因此,如果有人只想回答我的问题中的一点,这已经对我有帮助了。哇!非常感谢。你是说片段只是电话屏幕,对吗?我没想到。在德国是00:13,所以我不会请在工作结束后回复,并告知是否有效。非常感谢!是的,碎片将只显示在手机屏幕上,很高兴我能提供帮助!如果我能帮助您,请不要忘记投票并接受我的回答:)看来我只能以超过15个的声望来投票,对不起。我现在将尝试实施你的方法,我留下一个简短的问题^^^^这一切都发生在表面视图上。我需要一个保存电话框布局的东西,稍后我在其中初始化片段。是否可以用该布局打开一个新的城市,但是prevouse活动仍然可见?如我的图片所示?或者我是否在打开菜单时以编程方式将viewlayout添加到我的surfaceview中,并在关闭后将其删除?
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:propertyName="xFraction"
android:valueType="floatType"
android:valueFrom="1.0"
android:valueTo="0.0"
android:duration="750" />
// We get our FragmentManager and begin our transaction
FragmentManager manager = getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
// Here we set our animations, to make the effect nicer I added a fade out animation for the old fragment
// The fade out animation is already built into Android
transaction.setCustomAnimations(R.animator.slide_in_right, android.R.animator.fade_out);
// We specify were we want the Fragment to go and pass along our new fragment instance.
// Calls to replace(), add(), remove()... always have to take place AFTER setCustomAnimations()
// Otherwise the animations are not applied to the fragments
transaction.replace(R.id.flFragmentContainer, fragment);
// With commit() the transaction is actually executed. You can replace multiple fragments in a single transaction
transaction.commit();