private DrawerLayout drawerLayout; private FrameLayout fl; private ImageView iv; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); drawerLayout = (DrawerLayout) findViewById(R.id.drawerlayout); fl = (FrameLayout) findViewById(R.id.fl); iv = (ImageView) findViewById(R.id.iv); MainFragment01 mainFragment01=new MainFragment01(); iv.setImageResource(R.drawable.bg_account); getSupportFragmentManager().beginTransaction().replace(R.id.fl,mainFragment01).commit();}
布局文件
<FrameLayout android:id="@+id/fl" android:layout_width="match_parent" android:layout_height="match_parent" /> <ImageView android:id="@+id/iv" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="singleChoice" />
DrawerLayout的使用
最新推荐文章于 2025-07-25 15:30:17 发布
本文介绍了一个Android应用中的主Activity布局实现方式,并演示了如何通过FragmentManager进行Fragment的切换。此外,还展示了如何设置DrawerLayout及加载背景图片。
4万+

被折叠的 条评论
为什么被折叠?



