sách gpt4 ăn đã đi

java - 在创建 fragment 时使用 ConstraintLayout

In lại 作者:搜寻专家 更新时间:2023-10-30 21:26:24 29 4
mua khóa gpt4 giày nike

我想知道是否可以使用 ConstraintLayout 创建 fragment 布局!?这是一个正确的方法吗?或者是否有任何用于创建 fragment 的标准根元素?

câu trả lời hay nhất

Bạn có thể sử dụng ConstraintLayout 来包含 Mảnh vỡ。它也可以是 Mảnh vỡ 的基础 View 。但是,我通常使用 FrameLayout 作为容器,因为大多数时候没有理由使用复杂的布局,例如 ConstraintLayout

如您所见,FragmentTransaction.add() 没有对 containerViewId Xem 进行限制。

/**
* Add a fragment to the activity state. This fragment may optionally
* also have its view (if {@link Fragment#onCreateView Fragment.onCreateView}
* returns non-null) inserted into a container view of the activity.
*
* @param containerViewId Optional identifier of the container this fragment is
* to be placed in. If 0, it will not be placed in a container.
* @param fragment The fragment to be added. This fragment must not already
* be added to the activity.
* @param tag Optional tag name for the fragment, to later retrieve the
* fragment with {@link FragmentManager#findFragmentByTag(String)
* FragmentManager.findFragmentByTag(String)}.
*
* @return Returns the same FragmentTransaction instance.
*/
public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment, String tag);

同样 Fragment.onCreateView() 可以返回任何 View :

/**
* Called to have the fragment instantiate its user interface view.
* This is optional, and non-graphical fragments can return null (which
* is the default implementation). This will be called between
* {@link #onCreate(Bundle)} and {@link #onActivityCreated(Bundle)}.
*
*

If you return a View from here, you will later be called in
* {@link #onDestroyView} when the view is being released.
*
* @param inflater The LayoutInflater object that can be used to inflate
* any views in the fragment,
* @param container If non-null, this is the parent view that the fragment's
* UI should be attached to. The fragment should not add the view itself,
* but this can be used to generate the LayoutParams of the view.
* @param savedInstanceState If non-null, this fragment is being re-constructed
* from a previous saved state as given here.
*
* @return Return the View for the fragment's UI, or null.
*/
@Có thể rỗng
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState)

关于java - 在创建 fragment 时使用 ConstraintLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43886592/

29 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress