gpt4 book ai didi

android - 膨胀类 fragment : GoogleMaps inside FrameLayout 时出错

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

我正在尝试在 FrameLayout 中显示 GoogleMaps。此 FrameLayout 应该根据切换按钮上下移动。但是,当我尝试膨胀 View 时,我的应用程序崩溃了。

我在这里做的事情有可能吗?我的意思是在 FrameLayout 中显示 GoogleMaps?我怎样才能使它工作?

谢谢!

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/fragment_a"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/lv_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:text="Hello World!"/>
</RelativeLayout>
<!-- this frame is invisible -->
<FrameLayout
android:id="@+id/fragment_b"
android:visibility="invisible"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:background="#FF0000">
<fragment
android:id="@+id/map_v2"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</FrameLayout>
</LinearLayout>

我的 Fragment 类中的相应代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

final View rootView = inflater.inflate(R.layout.fragment_favorites, container, false);
final FragmentManager fm = getFragmentManager();
final RelativeLayout fragmentA = (RelativeLayout) rootView.findViewById(R.id.fragment_a);

fragmentA.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

RelativeLayout fragmentA = (RelativeLayout) getActivity().findViewById(R.id.fragment_a);
FrameLayout fragmentB = (FrameLayout)getActivity().findViewById(R.id.fragment_b);

int y = 200;
if (state == true) {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
fragmentA.animate().translationY(-y).setDuration(500);
fragmentB.animate().translationY(-y).setDuration(500);
state = false;
}
} else {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
fragmentA.animate().translationY(y).setDuration(500);
fragmentB.animate().translationY(y).setDuration(500);
state = true;
}
}
}
});
return rootView;
}

我得到的错误:

04-19 15:39:43.248    8758-8758/com.mahlzeit E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.mahlzeit, PID: 8758
android.view.InflateException: Binary XML file line #20: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:719)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.mahlzeit.mahlzeitactivity.FavoritesFragment.onCreateView(FavoritesFragment.java:27)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:953)

最佳答案

看起来你在嵌套 fragment 。 Fragment 布局中不能有 标签。

检查这里: Fragments within Fragments

使用 getChildFragmentManager() 动态添加 fragment 在你的 fragment 中。

关于android - 膨胀类 fragment : GoogleMaps inside FrameLayout 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29730820/

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