java - 我没有在 Fragment 类(top_section_fragment)中获得我的片段布局参考
问题描述
这是我的片段布局 top_section_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
>`enter code here`
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text1"
android:layout_centerHorizontal="true"
android:width="250dp"
android:height="50dp"
android:layout_marginTop="100dp"></EditText>
<Button
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="@+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="299dp"
android:text="Click Here"></Button>
</RelativeLayout>
这是我的片段类 TopSectionFragment.java
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import java.util.zip.Inflater;
public class TopSectionFragment extends Fragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.top_section_fragment)
return view;
}
}
我没有使用 R.layout.top_section_fragment 在片段类中获取我的片段布局
解决方案
这样做:
View view = inflater.inflate(R.layout.top_section_fragment, container, false);
return view;
推荐阅读
- ruby-on-rails - 如何结合 Rails I18n 语言环境,使用 en,但使用 es 表示 number.currency?
- docker - Docker 服务创建错误:没有合适的节点(3 个节点上的资源不足)
- android - 如何在android中创建自定义圆形卡片视图
- jquery - 客户端asp.net mvc上的Json结果未定义
- excel - Excel VBA查找单元格的最后一行并添加数据
- python - python conda:创建了一个环境,但它没有使用conda的python
- html - HTML 图像叠加定位
- sql - 试图从另一个视图创建一个视图?甲骨文顶点
- babeljs - 如何在 Babel 插件中复制 AST 分支?
- python - 交互性不适用于 matplotlib TkAgg 后端