[英]"center_horizontal is incompatible with attribute gravity...." New to xml and I don't understand what my issue is here
I am trying to make an app that has two buttons side by side, and a number above those buttons (with that whole arrangement being centered vertically on the screen).我正在尝试制作一个应用程序,它有两个并排的按钮,这些按钮上方有一个数字(整个排列在屏幕上垂直居中)。 The end goal is to eventually be able to have multiples of those but for now I just want to get at least one right.
最终目标是最终能够拥有这些的倍数,但现在我只想至少做一个正确的。 Anyway, for some reason I keep getting "failed linking file resources" as well as the error in the title.
无论如何,出于某种原因,我不断收到“链接文件资源失败”以及标题中的错误。 My code is below
我的代码在下面
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<TextView
android:text="0"
android:textSize="100sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_view1" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horiztonal">
<Button
android:text="+"
android:textSize="75sp"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="200px"
android:layout_weight="0.5"
android:id="@+id/button1" />
<Button
android:text="-"
android:textSize="75sp"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="200px"
android:layout_weight="0.5"
android:id="@+id/button2" />
</LinearLayout>
Do you want to achieve the result like following screenshot.你想达到如下截图所示的结果吗?
Please add following code, you should add </LinearLayout>
in the end, and set the android:orientation="vertical"
for the first LinearLayout
请添加以下代码,您应该在最后添加
</LinearLayout>
,并为第一个LinearLayout
设置android:orientation="vertical"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:gravity="center_horizontal"
>
<TextView
android:text="0"
android:textSize="100sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_view1" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horiztonal">
<Button
android:text="+"
android:textSize="75sp"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="200px"
android:layout_weight="0.5"
android:id="@+id/button1" />
<Button
android:text="-"
android:textSize="75sp"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="200px"
android:layout_weight="0.5"
android:id="@+id/button2" />
</LinearLayout>
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.