2010-07-28 26 views
0

我使用textview對象在我的遊戲屏幕上保存了Score,Level等標籤,但它們似乎並未顯示在我想要的位置。我瞭解視圖層次結構(父母,孩子),並使用XML佈局文件中的重力標籤,但似乎沒有任何影響。幫助在Android屏幕上安排TextView對象

有人可以快速提供一個指南來定位一個textview對象在屏幕上,也鏈接它的代碼,使其內容可以以編程方式控制(我相信這將通過=(TextView)完成findViewById(r .id.resourcename))?

非常感謝

XML:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
> 

    <android.gesture.GestureOverlayView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/gestures" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:gestureStrokeWidth="2.0" 


android:gestureStrokeType="multiple" 
android:eventsInterceptionEnabled="true"> 


<com.darius.android.distractions.DistractionsView 
    android:id="@+id/distractions_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 




<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <TextView 
     android:id="@+id/text" 
       android:text="Hello" 
       android:visibility="visible" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:gravity="center_horizontal" 
     android:textColor="#88ffffff" 
     android:textSize="24sp"/> 

     <TextView 
     android:id="@+id/textLevel" 
       android:text="@string/level_count" 
       android:visibility="visible" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:gravity="bottom" 
     android:textColor="#EB0000" 
     android:textSize="10sp"/> 


<TextView android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:text="@string/concentration_bar" 
      android:textColor = "#EB0000" 
      android:textSize="10sp" 
      android:id="@+id/conbartext" 
      android:visibility="visible"    

      ></TextView> 

</RelativeLayout> 

</android.gesture.GestureOverlayView> 
    </FrameLayout> 

回答

0

Common Layout Objects是一個很好的指導佈局的基本知識。重力標籤僅在某些佈局類型中有意義。

另一個有用的工具是Heirarchy Viewer,可在Android安裝的tools文件夾中找到。這使您可以查看正在運行的活動的視圖。

如果您發佈您的佈局XML以及您正在嘗試完成的模型,我們可能會幫助您實現它。

+0

有加我的XML。在面向橫向的屏幕上,我想將分數文本視圖標籤放在與整數分數變量鏈接的屏幕右下角,例如,它顯示「分數:1000」。例如,可能在左邊有一個類似的textview對象,例如「Level:3」。 非常感謝您的時間和幫助 – ComethTheNerd 2010-07-28 17:37:34