gpt4 book ai didi

java - fragment 未在家庭 Activity 中显示

转载 作者:行者123 更新时间:2023-12-01 18:15:25 25 4
gpt4 key购买 nike

我在 map Activity 上添加了抽屉导航。现在,我尝试在我的家庭 Activity 中添加一个 fragment ,但 fragment 未在 Activity 中显示,但 fragment 类中的代码正在运行。我的 FrameLayout 是否隐藏在 map fragment 后面?

我对 Fragments 很陌生。请帮助我。

首页布局

       <?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/constrain_layout"
android:orientation="vertical">


<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
map:layout_constraintBottom_toBottomOf="parent"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toTopOf="parent" />

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:layout_constraintBottom_toBottomOf="parent"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintHorizontal_bias="0.0"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toTopOf="parent"
map:layout_constraintVertical_bias="0.0"
tools:context=".HomeActivity" />

</androidx.constraintlayout.widget.ConstraintLayout>

fragment 类

public class RideHistory extends Fragment {

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

Toast.makeText(getActivity(), "Ride History", Toast.LENGTH_SHORT).show();
View view = inflater.inflate(R.layout.fragment_ride_history,container,false);
return view;
}

}

xml fragment

    <?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".Fragments.RideHistory">

<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Ride History" />

</FrameLayout>

最佳答案

更改布局约束,以便小部件框架布局和 map fragment 不会相互重叠。例如:

<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
map:layout_constraintBottom_toTopOf="@+id/map"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintStart_toStartOf="parent"
map:layout_constraintTop_toTopOf="parent" />
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="434dp"
android:layout_height="297dp"
map:layout_constraintBottom_toBottomOf="parent"
map:layout_constraintEnd_toEndOf="parent"
map:layout_constraintHorizontal_bias="0.0"
map:layout_constraintStart_toStartOf="parent"
tools:context=".HomeActivity" />

关于java - fragment 未在家庭 Activity 中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60378909/

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