2011-07-12 5 views
2

Je tente de créer une activité ListView avec une barre d'outils en haut. L'outil le plus à droite dans cette barre d'outils sera un gestionnaire vers un SlidingDrawer horizontal qui fournira un EditText coulissant au-dessus des autres outils. J'ai d'abord essayé d'obtenir ceci avec LinearLayout et FrameLayout, mais le curseur est allé autant que l'espace disponible moins la largeur totale des outils. En ce moment, je l'ai fait ce que je veux et fonctionne très bien avec la disposition suivante:Mise en page relative, SlidingDrawer et ListView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<RelativeLayout android:id="@+id/laytoptoolbarhost" 
    android:layout_width="fill_parent" 
    android:layout_height="55dip" 
    android:background="@drawable/toptoolbar_gradient" 
    android:padding="5dip"> 
    <View android:id="@+id/tool10" 
     android:layout_width="32dip" 
     android:layout_height="32dip" 
     android:paddingRight="3dip" 
     android:background="#00FF00" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true"> 
    </View>  
    <View android:id="@+id/tool20" 
     android:layout_width="32dip" 
     android:layout_height="32dip" 
     android:paddingRight="3dip" 
     android:background="#00FF00" 
     android:layout_toRightOf="@+id/tool10" 
     android:layout_centerVertical="true"> 
    </View> 
    <View android:id="@+id/tool30" 
     android:layout_width="32dip" 
     android:layout_height="32dip" 
     android:paddingRight="3dip" 
     android:background="#00FF00" 
     android:layout_toRightOf="@+id/tool20" 
     android:layout_centerVertical="true"> 
    </View>    
    <SlidingDrawer android:id="@+id/slidesearch" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:handle="@+id/sliderhandle" 
     android:content="@+id/txtsearch"> 
     <ImageView android:id="@+id/sliderhandle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/btn_collapse_states"> 
     </ImageView> 
     <EditText android:id="@+id/txtsearch" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="20sp"> 
     </EditText> 
    </SlidingDrawer> 
</RelativeLayout> 
<ListView android:id="@id/android:list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:drawSelectorOnTop="false"/> 
<TextView android:id="@id/android:empty" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:gravity="center" 
      android:textSize="20sp" 
      android:text="@string/lbl_norecords"/>  

Le problème est que je dois mettre une valeur fixe dans RelativeLayout Android: paramètre layout_height pour que cela fonctionne, . Si je place "wrap_content" alors RelativeLayout remplit tout l'écran et rien d'autre ne s'affiche.

Toute aide à ce sujet est très apprécié

Merci à l'avance

+0

C'est étrange, je soupçonne que la hauteur de l'un des enfants est à l'origine du problème, mais ils ont tous l'air ok pour moi. Parfois, la mise en page en termes relatifs entraîne des conséquences inattendues. Avez-vous essayé ceci avec une mise en page relative vide (barre d'outils) ou je devine juste un enfant parce que sa hauteur serait zéro autrement – Idistic

+0

J'ai essayé cela et la valeur de wrap_content fonctionne comme prévu. Je vais donc mettre un élément à la fois pour voir où ça va mal. Merci – Christos

+0

OK lorsque j'ajoute le SlidingDrawer le RelativeLayout commence à déconner. Je suis vraiment coincé ici ... – Christos

Répondre

2

Supprimez android:layout_centerVertical="true" des vues dans votre mise en page. J'ai également fait quelques changements à votre curseur pour arriver à ce que vous voulez. Les changements cruciaux au curseur sont:

  1. Ajouter: android:layout_alignTop="@+id/tool30" et android:layout_alignBottom="@+id/tool30"

  2. Retirez android:layout_alignParentRight="true" et android:layout_centerVertical="true"

J'ai fait quelques autres changements cosmétiques ailleurs lors du débogage de la mise en page.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <RelativeLayout 
     android:id="@+id/laytoptoolbarhost" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="5dip" 
     android:layout_weight="0"> 
     <View 
      android:id="@+id/tool10" 
      android:layout_width="32dip" 
      android:layout_height="32dip" 
      android:paddingRight="3dip" 
      android:background="#00FF00" 
      android:layout_alignParentLeft="true" 
      > 
     </View> 
     <View 
      android:id="@+id/tool20" 
      android:layout_width="32dip" 
      android:layout_height="32dip" 
      android:paddingRight="3dip" 
      android:background="#FFFF00" 
      android:layout_toRightOf="@+id/tool10" 
      > 
     </View> 
     <View 
      android:id="@+id/tool30" 
      android:layout_width="32dip" 
      android:layout_height="32dip" 
      android:paddingRight="3dip" 
      android:background="#00FFFF" 
      android:layout_toRightOf="@+id/tool20" 
      > 
     </View> 
     <SlidingDrawer 
      android:id="@+id/slidesearch" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:layout_alignTop="@+id/tool30" 
      android:layout_alignBottom="@+id/tool30" 
      android:handle="@+id/sliderhandle" 
      android:content="@+id/txtsearch"> 
      <ImageView 
       android:id="@+id/sliderhandle" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/alarm_clock"> 
      </ImageView> 
      <EditText 
       android:id="@+id/txtsearch" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:textSize="20sp"> 
      </EditText> 
     </SlidingDrawer> 
    </RelativeLayout> 
    <ListView 
     android:id="@id/android:list" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:drawSelectorOnTop="false" /> 
    <TextView 
     android:id="@id/android:empty" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:textSize="20sp" 
     android:text="nothing" 
     /> 
</LinearLayout> 
+0

Votre approche à la solution de mon problème m'a vraiment ouvert les yeux. Merci beaucoup pour votre temps. Certainement vous êtes le MANdel :-) – Christos

0

essayer autour de la RelativeLayout avec un LinearLayout où vous mettriez:
android:layout_width="wrap_content"
android:layout_width="wrap_content

changer alors le RelativeLayout d'un montant fixe de l'autre chose que vous pouvez faire est d'utiliser Droid Draw qui vous permettra de le mettre en évidence visuellement.

+0

Désolé Ephraim, cela ne fonctionne pas. Je reçois exactement les mêmes résultats ... – Christos

+0

pire scénario, il suffit d'utiliser droid draw pour l'exposer. Je vais modifier la réponse pour publier un lien. – Ephraim

0

Étant donné que vous avez déterminé que c'est le tiroir coulissant vous pouvez voir si cette discussion a une incidence (semble que vous pourriez être en mesure d'utiliser l'info)

SlidingDrawer height

Sinon je serais chercher un peu plus avec ce type de critères.

+0

Pour répondre à votre précédent commentaire sur la définition de la hauteur de la poignée en pixels, cela ne fonctionnait pas non plus. Donc, je vais essayer votre suggestion de réponses – Christos

Questions connexes