【问题标题】:Help Arranging TextView objects on screen in Android帮助在 Android 屏幕上排列 TextView 对象
【发布时间】:2010-07-28 17:11:18
【问题描述】:

我正在使用 textview 对象在我的游戏屏幕上保存诸如分数、级别等标签,但它们似乎没有显示在我想要的位置。我了解视图层次结构(父母、孩子)并且在 XML 布局文件中使用重力标签,但它似乎没有任何效果。

是否有人可以快速提供在屏幕上定位 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>

【问题讨论】:

    标签: android xml textview


    【解决方案1】:

    这些是一些关于开始使用 android 布局和小部件的非常有用的教程:http://developer.android.com/resources/tutorials/views/index.html

    有关布局本身的文档和指南在这里: http://developer.android.com/guide/topics/ui/declaring-layout.html

    【讨论】:

    • 啊,谢谢,阅读该教程并意识到布局的不同。信息量很大!
    【解决方案2】:

    Common Layout Objects 是一个很好的布局基础指南。重力标签仅在某些布局类型中有意义。

    另一个有用的工具是 Heirarchy Viewer,它位于 Android 安装的工具文件夹中。这使您可以可视化跑步活动的视图层次结构。

    如果您发布您的布局 XML,以及您想要完成的工作的模型,我们也许可以帮助您完成它。

    【讨论】:

    • 已添加我的 XML。在横向屏幕上,我想在屏幕右下方放置一个与整数分数变量相关联的分数 textview 标签,例如,它显示“分数:1000”。例如,也许在那个类似的 textview 对象的左侧,上面写着“Level:3”。非常感谢您的时间和帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    相关资源
    最近更新 更多