java - 使用片段
问题描述
无法在设备上正确显示片段。我有一个活动框架和一个片段框架。尝试用 Fragment 中的框架替换活动框架。但是我得到的是活动中的框架被混合在一起,下面的片段框架显示。
这是调用片段的代码。
public void setupMultiItems(String mScan){
Timber.d("Multiple matching Items");
Bundle bundle = new Bundle();
bundle.putString("valuesArray",mScan);
SelectItemFragment fragobj = new SelectItemFragment();
fragobj.setArguments(bundle);
FragmentManager fragmentManager=getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.FragmentFrame, fragobj);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
这是活动的 XML。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="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:background="@color/colorBackgroundGray"
tools:layout="@layout/fragment_select_item"
tools:context="com.procatdt.stockright.activities.PutAwayAreaActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<include
android:id="@+id/include2"
layout="@layout/frm1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_gravity="left"
android:layout_weight="1" />
<FrameLayout
android:id="@+id/FragmentFrame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:orientation="vertical">
<include
android:id="@+id/include"
layout="@layout/layout_numpad5"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="220dp"
android:layout_weight="1"
android:layout_gravity="right"
/>
</LinearLayout>
</RelativeLayout>
这是片段的 XML。
<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="com.procatdt.stockright.activities.SelectItemFragment">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/newFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<Button
android:id="@+id/btnSelectItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Select Item" />
</FrameLayout>
</RelativeLayout>
</FrameLayout>
活动的所有控件都被缩小并与下面显示的片段中的按钮一起卡住。
关于我所缺少的任何帮助。在过去的 18 年里,我的背景一直是 VB。这是我的第一个 Android Studio Java 项目,一直被碎片所困扰。
解决方案
推荐阅读
- spring-data-rest - 在哪里实施更改字段以根据业务规则复制实体
- excel - 撤消功能不适用于复制/粘贴操作
- node.js - 一些漏洞需要您注意解决
- typescript - 如何使用 TS Compiler API 查找变量在另一个文件中的定义位置
- python - 无法使用 rest api 和 python 获取并发布到 alm。总是得到 401 状态码
- postgresql - 无法识别的参数:--parquet-configurator-implementation
- python - 如何将数据分类为 N 类 + 一个“垃圾”类(或遗漏一些数据)?
- java - Java DOM:获取所有父母列表
- javascript - 不断刷新页面,直到特定单词消失
- flutter - 隐藏 SliverPersistentHeader 后如何更改视图