我正在用一个片段替换一个FrameLayout,但是它不会显示在屏幕上。我试图以编程方式添加它,以用ID @+id/fragment_vehicle_file_frame_menue
替换FrameLayout,但这会导致白屏。我还尝试将其添加到XML Ressource文件中,但是它也会导致白屏,即使我将Layout的backgroundColor设置为蓝色,它也会给我白屏。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:background="@color/color_hartmann_dark_grey">
<include layout = "@layout/layout_vehicle_information_header"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.36"
></include>
<FrameLayout
android:id="@+id/fragment_vehicle_file_frame_menue"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_hartmann_dark_green"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:fillViewport="true"
android:layout_margin="5dp"
android:layout_weight="0.45" >
<FrameLayout
android:id="@+id/fragment_vehicle_file_frame_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_hartmann_dark_green"
/>
</ScrollView>
</LinearLayout>
我也尝试过在布局中添加一个片段,但是它不会显示在屏幕上。我在另一个项目中构建了Fragment,并试图在该项目中实现它
以下是片段的代码:
public class fragment_listview extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_listview, container, false);
RecyclerView recyclerView = (RecyclerView) v.findViewById(R.id.recyclerList);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.HORIZONTAL));
ArrayList<String> items = new ArrayList<>();
TextView tv = v.findViewById(R.id.anzeigetafel);
CustomAdapter ca = new CustomAdapter(getContext(), items, tv);
recyclerView.setAdapter(ca);
for (int i = 1; i < 100 ; i++) {
items.add("Item Nr. "+ i);
ca.notifyDataSetChanged();
}
return v;
}
}