views:

30

answers:

2

Hi

I'm using textview objects to hold labels such as Score, Level etc on my game screen but they don't seem to be displayed where I want them to be. I understand about view hierarchies (parents, children) and am using the gravity tags in the XML layout file but it doesnt seem to have any effect.

Could someone just quickly provide a guide to positioning a textview object on the screen, and also linking it in the code so that its contents can be programmatically controlled (I believe this would by done via =(TextView) findViewById(r.id.resourcename))?

Many thanks

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

Common Layout Objects is a good guide to the basics of layouts. The gravity tag only has meaning in certain layout types.

Another useful tool is the Heirarchy Viewer, found in the tools folder of your Android installation. This allows you to visualize the View heirarchy of your running activity.

If you post your layout XML, and a mockup of what you are trying to accomplish, we might be able to help you accomplish it.

Mayra
Have added my XML. On a landscape oriented screen, i want to put a Score textview Label in the bottom right of the screen that is linked to the integer score variable so for example, it displays "Score: 1000". And perhaps to the left of that a similar textview object that says "Level: 3" for example.Many thanks for your time and help
Greenhouse Gases
A: 

These are some really helpful tutorials on getting started with android layout and widgets: http://developer.android.com/resources/tutorials/views/index.html

Documentation and a guide on the layout itself is here: http://developer.android.com/guide/topics/ui/declaring-layout.html

QRohlf
Ahh thanks, read that tutorial and realised the difference in layouts. Very informative!
Greenhouse Gases