Android RelativeLayout显示混乱

时间:2016-11-27 08:50:45

标签: android relativelayout

我有简单的RelativeLayout和多个元素。但是显示效果不如预期,有些元素混杂在一起。这对我来说似乎很奇怪,我无法弄清楚为什么会如此。请参阅随附的屏幕截图。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp" >

<Button
    android:id="@+id/btnClose"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="10dp"
    android:layout_marginTop="10dp"
    android:paddingTop="2dp"
    android:paddingBottom="2dp"
    android:background="#21759b"
    android:textColor="#FFFFFF"
    android:text="Close" />

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add a missing Business"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="20dp"
    android:textColor="#21759b"
    android:layout_below="@+id/btnClose"
    android:layout_centerHorizontal="true"/>

<Spinner
    android:id="@+id/spinnerContactType"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:minWidth="250dp"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:layout_below="@+id/title"
    android:entries="@array/contactType" />

<android.support.design.widget.TextInputLayout
    android:id="@+id/name_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginStart="2dp"
    android:layout_marginEnd="2dp"
    android:layout_marginTop="4dp"
    app:hintTextAppearance="@style/TextLabel"
    android:layout_below="@+id/spinnerContactType" >
    <EditText
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:maxLength="65"
        android:hint="Business Name" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:id="@+id/speciality_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginStart="2dp"
    android:layout_marginEnd="2dp"
    android:layout_marginTop="4dp"
    app:hintTextAppearance="@style/TextLabel"
    android:layout_below="@+id/name_layout" >
    <EditText
        android:id="@+id/speciality"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:maxLength="65"
        android:hint="Business speciality" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:id="@+id/address_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginStart="2dp"
    android:layout_marginEnd="2dp"
    android:layout_marginTop="4dp"
    app:hintTextAppearance="@style/TextLabel"
    android:layout_below="@+id/speciality_layout" >
    <EditText
        android:id="@+id/address"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:maxLength="65"
        android:hint="Business Address" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:id="@+id/name_phone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginStart="2dp"
    android:layout_marginEnd="2dp"
    android:layout_marginTop="4dp"
    app:hintTextAppearance="@style/TextLabel"
    android:layout_below="@+id/address_layout" >
    <EditText
        android:id="@+id/phone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:maxLength="65"
        android:hint="Business Phone" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:id="@+id/email_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginStart="2dp"
    android:layout_marginEnd="2dp"
    android:layout_marginTop="4dp"
    app:hintTextAppearance="@style/TextLabel"
    android:layout_below="@+id/phone_layout" >
    <EditText
        android:id="@+id/email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:maxLength="65"
        android:hint="Business Email" />
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:id="@+id/timings_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginStart="2dp"
    android:layout_marginEnd="2dp"
    android:layout_marginTop="4dp"
    app:hintTextAppearance="@style/TextLabel"
    android:layout_below="@+id/email_layout" >
    <EditText
        android:id="@+id/timings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:maxLength="65"
        android:hint="Business Timings" />
</android.support.design.widget.TextInputLayout>

<Button
    android:id="@+id/btnSubmit"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="100dp"
    android:layout_below="@+id/timings_layout"
    android:paddingTop="2dp"
    android:paddingBottom="2dp"
    android:background="#21759b"
    android:textColor="#FFFFFF"
    android:layout_centerHorizontal="true"
    android:text="Submit.." />

</RelativeLayout>
</ScrollView>

Screenshot here

5 个答案:

答案 0 :(得分:2)

您可以在这些情况下始终使用LinearLayout,但更容易管理 如果您不想更改,这是您的固定布局:

<?php
require "conn.php";
$sql = "select b.username from l_s a,user_table b where a.user_id=b.user_id    and status = 1";
$result = $conn->query($sql);
if ($result->num_rows >0) {
// output data of each row
while($row[] = $result->fetch_assoc()) {
$tem = $row;
$json = json_encode($tem);
}
} else {
echo "0 results";
}
echo json_encode($json);
$conn->close();
?>

  你使用 android:layout_below 时,你的代码的第一个问题是在你的情况下,你应该使用 @ id / view_id 因为你之前定义了那个视图而不是 @ + ID / view_id的

     

第二个问题是您添加了 android:layout_below =“@ id / phone_layout”而您没有定义 phone_layout 您只有的视图ID name_phone

希望这会有所帮助。

答案 1 :(得分:1)

在您的相对布局中使用

android:layout_height="wrap_content"

并为android:layout_marginTop设置正确的值{1}}还有一件事,但你还没有定义phone_layout

答案 2 :(得分:1)

我快速审核表明,标识为 def resetFields(self): self.name.set(value = '') #these work self.dob.set(value = '') for count, button in enumerate(self.buttons): self.buttons[count].config(value = -1) # nothing I have tried works. 的{​​{1}}使用TextInputLayout,其未使用的ID为email_layout

也许您的意思是引用layout_below。这样做(或者交替更改phone_layout id)似乎会删除重叠元素。

此外,我相信使用name_phone仅用于第一次参考,因此后续参考通常为name_phone

答案 3 :(得分:0)

让自己更轻松,并在垂直方向上使用LinearLayout。

答案 4 :(得分:0)

我想你希望email_layout低于phone_layout,但是看 - 你没有ID为phone_layout的布局 - 而不是你{{1} }} ID。因此,您只需将name_phone ID更改为name_phone即可。祝你好运:)

相关问题