6
我想在我的主要活動中將此xml轉換爲java,輸出爲導航抽屜。我只需要在這部分幫助,我完成了其餘部分。如何以編程方式創建DrawerLayout
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<FrameLayout
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<ListView
android:id="@+id/drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#FFF"
android:choiceMode="singleChoice"/>
我想上面寫Java代碼的XML,如何?
在此先感謝
更新
final DrawerLayout drawer = new android.support.v4.widget.DrawerLayout(this);
final FrameLayout fl = new FrameLayout(this);
fl.setId(CONTENT_VIEW_ID);
final ListView navList = new ListView (this);
drawer.addView(fl, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
drawer.addView(navList);
setContentView(drawer);
我需要一些幫助來定製列表視圖的佈局寬度和佈局重力代碼。
XML佈局使用情況如何? – gunar
我想在代碼中創建它,我在xml中不感興趣 – user289175