SlidingDrawer ne peut pas nouveau dans le code Java, car il faut définir la poignée et le contenu, mais vous pouvez gonfler dans la mise en page XML comme suit:
sliding_drawer.xml:
<?xml version="1.0" encoding="utf-8"?>
<SlidingDrawer
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:handle="@+id/handle"
android:content="@+id/content">
<ImageView
android:id="@id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/tray_handle_bookmark"
/>
<LinearLayout
android:id="@id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#FF000000"
/>
</SlidingDrawer>
Dans le code Java:
// you main Layout
LinearLayout mainLayout = new LinearLayout(this);
mainLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
mainLayout.setOrientation(LinearLayout.VERTICAL);
// add sliding Drawer
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
slidingDrawer = (SlidingDrawer)inflater.inflate(R.layout.sliding_drawer, mainLayout, false);
mainLayout.addView(slidingDrawer);
// get Layout for place your content in sliding drawer
LinearLayout slideContent = (LinearLayout)slidingDrawer.findViewById(R.id.content);
slideContent.addView(.....); // add your view to slideDrawer
SlidingDrawer est déjà disponible sur Android. Même si vous voulez le créer, regardez l'implémentation Android. – Karan
Je sais, mais je ne » comprendre comment utiliser ce constructeur SlidingDrawer (contexte de contexte, attrs AttributeSet) Comment créer un AttributeSet? – Alex