将文本视图添加到布局中?

2024-05-08

如果我的按钮不移动,我就无法在按钮上方放置文本视图...我该如何解决这个问题?

被困在这个问题上 4 个小时了...这很伤心,因为我正在尝试在我的布局上添加一个文本视图...

我的布局中心有 4 个按钮。我只想在四个按钮上方添加一个文本视图,如下所示(TextView 应该位于红色的位置):

当我将文本视图放置在按钮上方时,XML 布局视图中的拖放功能将不起作用。它只是使按钮居中。我也尝试过做什么this https://stackoverflow.com/questions/7887815/android-how-do-i-position-views-in-an-offset-relative-to-the-center-top-bottom建议回答,但锚视图本身不会位于中心!

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.me.circleswithmap.MainActivity"
    android:id="@+id/layout"
    android:gravity="center">

    <ImageButton
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/Blue"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="@drawable/bluesquare" />

    <ImageButton
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/Green"
        android:layout_below="@+id/Blue"
        android:layout_alignLeft="@+id/Blue"
        android:layout_alignStart="@+id/Blue"
        android:background="@drawable/greensquare" />

    <ImageButton
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/Red"
        android:layout_alignTop="@+id/Blue"
        android:layout_toRightOf="@+id/Blue"
        android:layout_toEndOf="@+id/Blue"
        android:background="@drawable/redsquare" />

    <ImageButton
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/Purple"
        android:layout_alignBottom="@+id/Green"
        android:layout_alignLeft="@+id/Red"
        android:layout_alignStart="@+id/Red"
        android:background="@drawable/purplesquare" />



    NEED SOME TEXTVIEW ALSO! WHENEVER I ADD ONE, IT DISCENTERS THE REST OF THE BUTTONS!


</RelativeLayout>

我应该怎么做才能解决这个问题?为什么这么难?我不应该使用相对布局吗?我怎样才能阻止它们相互关联?

非常感谢,

空指针异常


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context="com.example.ruchir.circleswithmap.MainActivity"
                android:id="@+id/layout">

    <LinearLayout android:layout_width="wrap_content"
                  android:id="@+id/text_container"
                  android:layout_centerInParent="true"
                  android:layout_alignParentTop="true"
                  android:layout_height="wrap_content">
        <TextView android:layout_width="match_parent"
                  android:text="pruebaskjahlkdjahslk"
                  android:layout_height="match_parent"/>
    </LinearLayout>

    <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_centerInParent="true"
            android:layout_height="wrap_content">

        <ImageButton
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/Blue"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"/>

        <ImageButton
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/Green"
                android:layout_below="@+id/Blue"
                android:layout_alignLeft="@+id/Blue"
                android:layout_alignStart="@+id/Blue"/>

        <ImageButton
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/Red"
                android:layout_alignTop="@+id/Blue"
                android:layout_toRightOf="@+id/Blue"
                android:layout_toEndOf="@+id/Blue"/>

        <ImageButton
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/Purple"
                android:layout_alignBottom="@+id/Green"
                android:layout_alignLeft="@+id/Red"
                android:layout_alignStart="@+id/Red"/>

    </RelativeLayout>
</RelativeLayout>

横向

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context="com.example.me.circleswithmap.MainActivity"
                android:id="@+id/layout">

    <LinearLayout android:layout_width="wrap_content"
                  android:id="@+id/text_container"
                  android:layout_height="wrap_content"
                  android:layout_centerHorizontal="true">
        <TextView
                android:layout_width="match_parent"
                android:text="20:00"
                android:layout_height="match_parent"
                android:textAppearance="?android:attr/textAppearanceLarge"
                />
    </LinearLayout>

    <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/relativeLayout"
            android:layout_below="@id/text_container"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            >

        <ImageButton
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/Blue"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"/>

        <ImageButton
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/Green"
                android:layout_below="@+id/Blue"
                android:layout_alignLeft="@+id/Blue"
                android:layout_alignStart="@+id/Blue"/>

        <ImageButton
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/Red"
                android:layout_alignTop="@+id/Blue"
                android:layout_toRightOf="@+id/Blue"
                android:layout_toEndOf="@+id/Blue"/>

        <ImageButton
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/Purple"
                android:layout_alignBottom="@+id/Green"
                android:layout_alignLeft="@+id/Red"
                android:layout_alignStart="@+id/Red"/>

    </RelativeLayout>

</RelativeLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将文本视图添加到布局中? 的相关文章

随机推荐

  • 具有漫反射和法线贴图纹理的 3D 模型

    我想使用 libgdx 的资源加载器加载具有漫反射纹理和法线贴图的 3D 模型 据我所知 fbx 以及转换后的 g3dj g3db 格式可以包含漫反射纹理 正如我在 fbx conv 示例中看到的那样 骑士 g3db 如何为其添加法线贴图纹
  • 如何使用 Kotlin 在 ListAdapter 中使用 Filterable?

    我会用一个SearchView过滤我的RecyclerView 在 stackoverflow 和其他网站上我发现只是使用的示例Filterable与 Java 和RecyclerView Adapter当我使用时ListAdapter 所
  • 在 Phaser3 中从 Multiatlas 加载文件时出错

    尝试使用 Phaser 和 TexturePacker 中的多图集功能 出现此错误 VM32201 1 GET http localhost 8080 bg sd json 404 Not Found Texture js 250 Text
  • 如何过滤 pyspark 列表中值的列?

    我有一个数据框原始数据 我必须在 X 列上应用值 CB CI 和 CR 的过滤条件 所以我使用了下面的代码 df dfRawData filter col X between CB CI CR 但我收到以下错误 Between 恰好需要 3
  • Hibernate 工具无法检测一对一关系

    我正在尝试使用 Eclipse 中的 Hibernate 工具 注释 从 MySQL 数据库生成实体类 但是 我在生成一对一关系代码时遇到了麻烦 我的 MySQL 表当前正在确保这种关系 但 Hibernate 工具无法检测到它 一个用户与
  • 我的 POST 编辑操作是否会覆盖 EF 中的所有字段?

    假设我有一个包含 7 个字段的数据库记录 我只想编辑字段 1 的内容 所以我点击了 GET EDIT 操作 它使用我的视图模型呈现强类型视图 然后我继续更新字段 1 但是 我的POST 操作包含所有字段的 映射 如下所示 实体框架也是如此
  • 如何使用canvas获取html5中的视频截图

    您好 是否可以使用 html 5 canvas 捕获正在播放的视频的屏幕截图 看起来这里是可能的 http html5doctor com video canvas magic http html5doctor com video canv
  • 无法使用 Mockito 模拟 Spring-Data-JPA 存储库

    我正在尝试为服务编写测试 但我没有成功地嘲笑repository依赖性 其他非存储库依赖项已成功模拟 存储库实例始终是实际实现 而不是模拟实例 我正在使用 Spring Boot 和 Spring Data JPA 来构建应用程序 Mock
  • 从函数正确传播“decltype(auto)”变量

    这是来自 decltype auto 变量有任何实际用例吗 https stackoverflow com questions 57438217 are there any realistic use cases for decltypea
  • 使用步骤 c++ 构建向量

    是否可以在不使用 C 中的循环的情况下以固定步骤创建从一个值到另一个值的向量 例如 我想用步长 0 5 构建一个从 1 到 10 的向量 在 MATLAB 中我可以按如下方式执行此操作 vector 1 0 5 10 c 中有类似的东西吗
  • 如何使用 apache commons cli 指定多个选项?

    我想要这样的东西 java programName jobs1 C 10 W 20 java programName job2 java programName job3 含内容 Option o1 new Option job2 some
  • 人体的宽度和高度

    如何识别图像中人体的高度和宽度 你需要一些参考点 除非您知道相机设置 位置 变焦 镜头畸变等 以及人相对于相机的位置 否则简单的照片是不够的 如果您确实有参考 例如背景中的网格或其他东西 那么您可以测量网格并从那里开始 听起来不像你需要的
  • 扭曲的C++代码[重复]

    这个问题在这里已经有答案了 可能的重复 未定义的行为和序列点 https stackoverflow com questions 4176328 include lt iostream h gt int main int i 7 j i j
  • 正则表达式的替代(流畅?)界面设计

    我刚刚看到了一个巨大的 Java 正则表达式 这让我对正则表达式的一般可维护性进行了一些思考 我相信大多数人 除了一些糟糕的 Perl 贩子 都会同意正则表达式很难维护 我正在考虑如何解决这种情况 到目前为止 我最有希望的想法是使用流畅的界
  • ListView 中的焦点控件

    上下文 我想要一个不会获得焦点的 ListView 例如不会 当用户触摸它时突出显示该行 然而每个行小部件都有它自己的 OnClickListener 这是我在布局 xml 中指定的内容 android choiceMode none an
  • Chrome 扩展 |有什么方法可以让 chrome.storage.local.get() 返回一些东西吗?

    在我的 chrome 扩展中 我需要使用 chrome 存储 在我的后台脚本中 我首先创建一个对象并将其添加到 chrome 存储中 然后我想从那里获取我的对象并返回 像这样的东西 var obj chrome storage local
  • 使用 Sinon.js 并阻止调用我的应用程序服务器

    足够简单的问题 我希望我们 sinon js 测试一段 javascript 以确保它调用 ajax方法同时做两件事 我不想真正访问服务器 我想模拟来自服务器的响应 所以这是 JS ajax url tickets id json data
  • 如何在iOS 11中向集合视图大标题导航栏添加刷新控件?

    根据 Apple 的说法 刷新控件应该是 iOS 11 中大标题导航栏的一部分 当我在故事板中为 UITableViewController 启用刷新控件时 刷新控件是导航栏的一部分 拉动刷新 我无法在故事板中为 UICollectionV
  • 如何在 iOS8 上以编程方式创建一个没有 Storyboard 的 Today 小部件?

    我尝试删除故事板文件和相关的Info plist进入但这次扩展停止工作 它甚至不能从 XCode 启动 The operation couldn t be completed LaunchServicesError error 0 在常规应
  • 将文本视图添加到布局中?

    如果我的按钮不移动 我就无法在按钮上方放置文本视图 我该如何解决这个问题 被困在这个问题上 4 个小时了 这很伤心 因为我正在尝试在我的布局上添加一个文本视图 我的布局中心有 4 个按钮 我只想在四个按钮上方添加一个文本视图 如下所示 Te