2010-05-14 5 views
1

J'essaye de créer un tiroir coulissant dans le code, mais je ne comprends pas quoi faire pour la partie AttributeSet du constructeur.Comment créer un tiroir coulissant dans le code?

Que dois-je faire pour cela?

De même, comment définir dans le code où le curseur va apparaître?

Merci,

+0

SlidingDrawer est déjà disponible sur Android. Même si vous voulez le créer, regardez l'implémentation Android. – Karan

+0

Je sais, mais je ne » comprendre comment utiliser ce constructeur SlidingDrawer (contexte de contexte, attrs AttributeSet) Comment créer un AttributeSet? – Alex

Répondre

2

Il ressemble à SlidingDrawer ne peuvent pas être créés directement dans le code Java. Vous devrez le définir dans une mise en page XML et gonfler cette mise en page.

Désolé!

+0

Très bien merci pour la réponse – Alex

7

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