Java 相对查看5个按钮,don';我不理解我的错误
我正在尝试为自己制作一个应用程序来跟踪我在健身房的进度,因为这是我的新年决心之一。。。我不去健身房,我想如果我能跟踪进度,我可能会有兴趣回去 这是我的问题: 我现在正在做我的主布局,我想要一个大按钮,上面写着:开始训练。 我想有4个按钮居中,彼此相邻,彼此之间有一些空间,四个按钮合在一起会有一个正方形的形式 我写了这段代码,现在什么都没用。我都不知道该去哪里找了。我知道我可以使用LinearLayout,但我在任何地方都读到相对论应该优先考虑Java 相对查看5个按钮,don';我不理解我的错误,java,android,android-relativelayout,Java,Android,Android Relativelayout,我正在尝试为自己制作一个应用程序来跟踪我在健身房的进度,因为这是我的新年决心之一。。。我不去健身房,我想如果我能跟踪进度,我可能会有兴趣回去 这是我的问题: 我现在正在做我的主布局,我想要一个大按钮,上面写着:开始训练。 我想有4个按钮居中,彼此相邻,彼此之间有一些空间,四个按钮合在一起会有一个正方形的形式 我写了这段代码,现在什么都没用。我都不知道该去哪里找了。我知道我可以使用LinearLayout,但我在任何地方都读到相对论应该优先考虑 <?xml version="1.0" enc
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
<Button
android:id="@+id/start_workout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="@string/start_workout"
/>
<Button
android:id="@+id/log_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:hint="@string/log_button"
/>
<Button
android:id="@+id/progress_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:hint="@string/progress_button"
/>
<Button
android:id="@+id/cardio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/calendar_button"
android:layout_below="@id/progress_button"
android:hint="@string/cardio_button"
/>
<Button
android:id="@+id/calendar_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/cardio_button"
android:layout_below="@+id/log_button"
android:hint="@string/calendar_button" />
</RelativeLayout>
试试这个,但最好在您的案例中使用线性布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<Button
android:id="@+id/cardio_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/log_button"
android:hint="cardio_button" />
<Button
android:id="@+id/progress_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/log_button"
android:layout_alignBottom="@+id/log_button"
android:layout_toRightOf="@+id/cardio_button"
android:hint="progress_button" />
<Button
android:id="@+id/calendar_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/cardio_button"
android:layout_alignBottom="@+id/cardio_button"
android:layout_toRightOf="@+id/cardio_button"
android:hint="calendar_button" />
<Button
android:id="@+id/log_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/start_workout"
android:layout_marginTop="50dp"
android:layout_toLeftOf="@+id/progress_button"
android:hint="log_button" />
<Button
android:id="@+id/start_workout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:hint="start_workout" />
</RelativeLayout>
在这里
第一个按钮是屏幕宽且顶部对齐的
其他四个占据屏幕宽度的1/4,并且都在顶部下方
<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=".MainActivity"
>
<Button
android:id="@+id/start_workout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Start workout"
android:textSize="12sp"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/start_workout"
android:orientation="horizontal"
>
<Button
android:id="@+id/cardio_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cardio"
android:textSize="12sp"
/>
<Button
android:id="@+id/progress_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Progress"
android:textSize="12sp"
/>
<Button
android:id="@+id/calendar_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Calendar"
android:textSize="12sp"
/>
<Button
android:id="@+id/log_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Log"
android:textSize="12sp"
/>
</LinearLayout>
</RelativeLayout>
您能分享一下所需结果的图片吗?这五个按钮应该垂直堆叠还是水平排列?你想要一个中心的一个和四个缝合在其两侧?尝试设置相对属性的属性为:Android:LayOutSuffel=“FILIL Primon”的Android:LayOutoSHILL =“FILIL Prime'”,我想要一个中央的一个上面,四个小的正方形在屏幕2x2的中间。谢谢!这正是我想要的太棒了!那么,你能把我的回答标为接受并投票吗?非常感谢,谢谢!