2010-11-19 4 views
0

Est-il possible d'obtenir la largeur d'une disposition linéaire/relative, si layout_width est défini sur fill_parent dans la structure xml? Par exemple, j'ai la mise en page xml suivante. Est-il possible de trouver la largeur de la cameraSourceScreen? Merci d'avance :)Obtenir la largeur de la disposition linéaire/relative?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:id="@+id/CameraSourcesScreen" 
> 

<LinearLayout android:id="@+id/button_bar" 
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:layout_alignParentTop="true" 
android:layout_alignParentLeft="true" 
android:background="@drawable/topbar" 
android:orientation="horizontal" 
android:gravity="center"> 

<LinearLayout android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:orientation="horizontal" android:paddingLeft="20dp"> 

     <common.view.ToggleButton android:id="@+id/Near_Toggle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="2dp" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" android:text="@string/NEAR_STR" 
      android:textSize="18px" android:width="130dp"/> 

    <common.view.ToggleButton android:id="@+id/Far_Toggle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="2dp" 
      android:layout_alignParentLeft="true" 
      android:layout_centerVertical="true" android:text="@string/FAR_STR" 
      android:textSize="18px" android:width="130dp"/> 

</LinearLayout> </LinearLayout> </RelativeLayout> 

Répondre

4

Vous pouvez ajouter un androïde: id à votre RelativeLayout, puis appelez findViewById comme vous le faites pour le reste des widgets, puis utiliser la méthode getWidth. Bien que ... il semble que votre RelativeLayout remplisse tout l'écran, alors pourquoi ne pas simplement essayer de connaître les dimensions de l'écran?

Display display = getWindowManager().getDefaultDisplay(); 
display.getWidth(); 
+0

Whoa, ne savait pas que je pourrais faire ça ... Merci :) – iman453

+0

il ne serait pas remplir l'écran sur Android ICS + car il y a une barre de bouton graphique sur le fond. – Fresheyeball

Questions connexes