【问题标题】:Android - Layout not appearing as expected [duplicate]Android - 布局未按预期显示[重复]
【发布时间】:2017-12-11 15:02:08
【问题描述】:

这(第一张图片)是布局在 content_main.xml 中的显示方式 https://s8.postimg.org/8ie65tzdh/Untitled1.png 但这(第二张图片)是它在虚拟设备中的显示方式。 https://s8.postimg.org/wywc0enad/Untitled.png

我是初学者,所以我可能会在这里遗漏很多东西。我们将不胜感激。

<?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:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.shanu.namerank.MainActivity"
tools:showIn="@layout/activity_main">

<Button
    android:id="@+id/submit"
    style="@style/Widget.AppCompat.Button.Colored"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="216dp"
    android:layout_marginBottom="246dp"
    android:layout_marginLeft="132dp"
    android:layout_marginRight="132dp"
    android:text="@string/submit"
    tools:layout_editor_absoluteX="136dp"
    tools:layout_editor_absoluteY="217dp" />

<EditText
    android:id="@+id/name"
    android:layout_width="279dp"
    android:layout_height="70dp"
    android:layout_marginTop="128dp"
    android:layout_marginBottom="310dp"
    android:layout_marginLeft="40dp"
    android:layout_marginRight="40dp"
    android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    android:ems="10"
    android:inputType="textPersonName"
    android:text="@string/enter_name"
    tools:layout_editor_absoluteX="41dp"
    tools:layout_editor_absoluteY="129dp" />

<Button
    android:id="@+id/check"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/check"
    android:layout_marginTop="283dp"
    android:layout_marginBottom="176dp"
    android:layout_marginLeft="124dp"
    android:layout_marginRight="124dp"
    tools:layout_editor_absoluteX="126dp"
    tools:layout_editor_absoluteY="284dp" />

<TextView
    android:id="@+id/result"
    android:layout_width="194dp"
    android:layout_height="67dp"
    android:layout_marginTop="356dp"
    android:layout_marginBottom="88dp"
    android:layout_marginLeft="80dp"
    android:layout_marginRight="80dp"
    android:text="@string/result"
    tools:layout_editor_absoluteX="83dp"
    tools:layout_editor_absoluteY="357dp" />


</android.support.constraint.ConstraintLayout>

enter image description here

【问题讨论】:

  • 图片在哪里?
  • 使用正确的网址编辑您的问题。
  • 您忘记添加图片
  • 我上传了图片的链接。

标签: android android-layout


【解决方案1】:

您需要添加“android:layout_marginBottom= x dp”。 所有 4 个边的底部/顶部/开始(左侧)/结束(右侧)。对于每个元素。

或者,如果您喜欢更多的设计方面,只需将箭头从元素拉到侧面,然后将元素移动到布局上。

【讨论】:

  • 但即使添加了边距,它看起来还是一样的。
  • 这里是受约束元素imgur.com/gXC0sHN 的示例。但我发现使用这些箭头更容易,只需将其拖到布局上即可。
【解决方案2】:

您的视图有限制,这些限制仅用于在 xml 布局编辑器中显示,但在实际设备上运行时会被忽略。 Android Studio 应该会就使用任何带有“layout_editor_”文本的内容向您发出警告。你需要给视图真正的约束。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-12
    • 2017-11-14
    • 1970-01-01
    • 1970-01-01
    • 2016-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多