簡體   English   中英

替換片段不顯示整個片段

[英]Replace fragment don't show the whole fragment

您好,我試圖用片段替換FrameLayout中的視圖。 我想使它像Android指南中那樣,當我創建片段並且它沒有足夠的空間時,它會創建新的Activity。 android方面的示例

我有問題。 我的片段容器是FrameLayout

    <FrameLayout
    android:id="@+id/fragment"
    android:layout_width="344dp"
    android:layout_height="0dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"/>

片段事務套件將我的片段調整為FrameLayout的大小。 這使得我的片段不是全部可見(它的布局大於FrameLayout的大小),我不知道為什么會有這個問題。 這是我的片段交易代碼(當我單擊“文本視圖”時顯示):

        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

    transaction.add(R.id.fragment, new FragmentPlan());
    transaction.commit();

我的片段

    public class FragmentPlan extends Fragment {
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_plan, container, false);
        ButterKnife.bind(this, view);
        return view;
    }
}

我相信您的代碼運行正常。

當您用片段添加/替換viewGroup時,該片段會從viewGroup繼承大小,因此,它很小。

如我所見,您可以增加frameLayout的大小。 或像上面在注釋中提到的那樣,使用一個Intent來啟動一個新的Activity。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM