如何解决我的按钮和文本显示在Android Studio 4.0的错误位置
嗨,我正在练习可点击按钮,为此,我需要在此处复制设计: https://www.figma.com/file/pAx28mFg68qvYulJQcyMHE/Score-Tracker?node-id=0%3A1
但是出于某种原因,尽管我相信我正确地编写了所有尺寸,但是我无法将按钮和零位放置在应该放置的确切位置,我也不知道为什么!
这是我的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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/background"/>
<TextView
android:id="@+id/numberOfGoals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="163dp"
android:layout_marginTop="124dp"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="72sp"/>
<TextView
android:id="@+id/numberOfGoals2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="163dp"
android:layout_alignTop="@id/Button2"
android:layout_marginBottom="124dp"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="72sp"/>
<Button
android:id="@+id/Button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Goal"
android:textColor="#FFFFFF"
android:textSize="14sp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="14dp"
android:backgroundTint="#EB5757"
android:layout_alignParentTop="true"/>
<Button
android:id="@+id/Button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Goal"
android:backgroundTint="#EB5757"
android:textColor="#FFFFFF"
android:textSize="14sp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="14dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</LinearLayout>
</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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/background">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/background"/>
<TextView
android:id="@+id/numberOfGoals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/Button1"
android:layout_centerHorizontal="true"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="72sp"/>
<TextView
android:id="@+id/numberOfGoals2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/Button2"
android:layout_centerHorizontal="true"
android:text="0"
android:textColor="#FFFFFF"
android:textSize="72sp"/>
<Button
android:id="@+id/Button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Goal"
android:textColor="#FFFFFF"
android:textSize="14sp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="14dp"
android:backgroundTint="#EB5757"
android:layout_alignParentTop="true"/>
<Button
android:id="@+id/Button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Goal"
android:backgroundTint="#EB5757"
android:textColor="#FFFFFF"
android:textSize="14sp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="14dp"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。