[英]Fragment is not showing its full width and Height
我正在我的android應用程序中創建一個滑動菜單。 但是在運行時,我的所有片段都沒有顯示出由“ match_parent”設置的完整大小。
**這是圖像:**
這是我的代碼
版面:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@android:color/holo_red_light"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
Java代碼:
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.nav_place_order:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new PlaceOrderPage1Fragment()).commit();
break;
case R.id.nav_profile:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new ProfileFragment()).commit();
break;
case R.id.nav_settings:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new SettingsFragment()).commit();
break;
case R.id.sample:
Toast.makeText(this,"Sample",Toast.LENGTH_SHORT).show();
break;
}
檢查您的片段onCreateView()
方法
您應該像這樣膨脹視圖:
val root = inflater.inflate(R.layout.list_content,container, false);
return root
並確保在進行片段交易時添加片段的place_holder
可見
fragmentTransaction.replace(R.id.fragment_container, YourFragment())
在上面的代碼中,請確保fragment_container可見並且具有適當的高度和寬度
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.