2010-11-19 11 views
0

layout_widthがlayout xmlのfill_parentに設定されていると、線形/相対レイアウトの幅を取得できますか?たとえば、次のレイアウトxmlがあります。 cameraSourceScreenの幅を見つけることは可能ですか?事前のおかげ:)線形/相対レイアウトの幅を取得しますか?

<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> 

答えて

4

にあなたはアンドロイドを追加することができます。idあなたのRelativeLayoutに、その後のgetWidthメソッドを使用し、あなたがそうであるように、ウィジェットの残りのためfindViewByIdを呼び出して。しかし、あなたのRelativeLayoutがすべての画面を満たしているようですが、画面の寸法を知りたいのですが?

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

おっとは、下の上のグラフィックボタンバーがあるので... – iman453

+0

:)おかげで、それはアンドロイドICS +の画面を埋めることはないだろうと私は知りませんでした。 – Fresheyeball

関連する問題