0

我想在 android 的卡片视图中显示一个片段。需要帮助。我已经制作了一些片段,比如说其中之一是 Settings_fragment.xml

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/cardView1"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="20dp"
    card_view:cardUseCompatPadding="true"
    card_view:cardCornerRadius="4dp"
    card_view:cardElevation="4dp"
    card_view:contentPadding="10dp">

    <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/frame">

           //HERE I WANT TO SHOW A FRAGMENT

    </FrameLayout>

</android.support.v7.widget.CardView>
4

2 回答 2

3

在 CardView 内添加 FrameLayout。然后在 Activity 中获取该框架布局引用并使用addView()方法添加该片段。

例子:

YourFragment fragment = new YourFragment();
Framelayout layout = (FrameLayout) findViewById(R.id.frameLayout);
layout.addView(fragment);
于 2015-12-01T10:29:19.457 回答
2

卡片视图是一个框架布局。所以只需将片段直接添加到卡片视图并将其视为框架布局。

于 2017-08-09T04:17:27.550 回答