【问题标题】:noob Q: layout_below not placing my button below my textView菜鸟问:layout_below 没有将我的按钮放在我的 textView 下方
【发布时间】:2017-07-10 14:58:51
【问题描述】:

非常新,所以请原谅滥用术语。

我正在学习一个 Android 开发课程来构建一个基本的应用程序。我创建了一个文本视图,然后创建了一个按钮。使用android:layout_below="@id/rollResult" 后,按钮应位于文本视图下方,但按钮与文本重叠。

在我的代码中添加和删除该行对按钮的布局位置没有影响。将此行 android:layout_centerHorizontal="true" 从 true 更改为 false 并返回也没有效果。

代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.diceout.MainActivity"
tools:showIn="@layout/activity_main"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">

<TextView
    android:id="@+id/rollResult"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="The play App"
/>

<Button
    android:id="@+id/rollButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/rollResult"
    android:layout_centerHorizontal="true"
    android:onClick="rollDice"
    android:text="Roll" />

非常感谢任何帮助。

【问题讨论】:

    标签: java android xml layout


    【解决方案1】:

    将您的 ConstraintLayout 更改为 RelativeLayout

    【讨论】:

    • 哇,谢谢!那行得通。现在一切都按原样排列。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2020-01-03
    • 2018-11-14
    • 2012-09-26
    相关资源
    最近更新 更多