简体   繁体   English

“center_horizo​​ntal 与属性重力不兼容....” xml 新手,我不明白我的问题是什么

[英]"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.

相关问题 EditText:重力=“ center_horizo​​ntal”不起作用 - EditText: gravity=“center_horizontal” isn't working android:重力center_horizo​​ntal linearlayot不起作用 - android: gravity center_horizontal linearlayot doesn't work “重力”不包含“CENTER_HORIZONTAL”的定义 - 'Gravity' does not contain a definition for 'CENTER_HORIZONTAL' 即使属性为android:layout_gravity =“ center_horizo​​ntal”,小部件也会出现在左侧 - Widget appears in the left even with attribute android:layout_gravity=“center_horizontal” android:layout_gravity =“ center_horizo​​ntal”在Java代码中 - android:layout_gravity=“center_horizontal” in Java code RelativeLayout-android:layout_centerHorizo​​ntal =“ true”和android:gravity =“ center_horizo​​ntal”显示意外结果 - RelativeLayout - android:layout_centerHorizontal=“true” AND android:gravity=“center_horizontal” showing unexpected results 在RelativeLayout中对齐元素,使其中一个为center_horizo​​ntal - Aligning elements in a RelativeLayout such that one is center_horizontal 我不明白我的规则有什么问题 - I don't understand what's wrong with my rules “center_horizo​​ntal | center_vertical”和“center”之间有什么区别吗? - Is there any difference between “center_horizontal|center_vertical” and “center” 如何在bottom_vertical对齐小部件 与RelativeLayout一起使用的center_horizo​​ntal - How to align a widget at bottom_vertical | center_horizontal with RelativeLayout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM