android studio按钮可见性

android studio按钮可见性,android,android-studio,kotlin,Android,Android Studio,Kotlin,我有一个非常简单的活动,其中包括一个按钮,并链接到第二个活动 问题是该按钮不会显示在应用程序中 我的编辑器中有按钮,但当我创建apk文件时,我的应用程序中没有按钮 应用程序内 编者 有什么想法吗?使用线性布局作为父布局 我想你的按钮跳到(0,0)。 请使用线性布局作为父布局 然后在线性布局中添加按钮。使用线性布局作为父布局 我想你的按钮跳到(0,0)。 请使用线性布局作为父布局 然后在线性布局中添加按钮。如果要使按钮位于屏幕中央,只需使用android:layout\u centerIn

我有一个非常简单的活动,其中包括一个按钮,并链接到第二个活动

问题是该按钮不会显示在应用程序中

我的编辑器中有按钮,但当我创建apk文件时,我的应用程序中没有按钮

应用程序内

编者



有什么想法吗?

使用线性布局作为父布局 我想你的按钮跳到(0,0)。 请使用线性布局作为父布局
然后在线性布局中添加按钮。

使用线性布局作为父布局 我想你的按钮跳到(0,0)。 请使用线性布局作为父布局
然后在线性布局中添加按钮。

如果要使按钮位于屏幕中央,只需使用android:layout\u centerInParent=“true”

用这个

<Button
        android:id="@+id/button"
        android:layout_width="171dp"
        android:layout_height="55dp"
        android:layout_centerInParent="true"
        android:text="alphabetButton" />

而不是这个

<Button
        android:id="@+id/button"
        android:layout_width="171dp"
        android:layout_height="55dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="119dp"
        android:layout_marginLeft="119dp"
        android:layout_marginTop="186dp"
        android:layout_marginEnd="121dp"
        android:layout_marginRight="121dp"
        android:layout_marginBottom="362dp"
        android:text="@string/alphabetButton" />

示例代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:lineSpacingExtra="8sp"
        android:text="@string/selamatDatang"
        android:textColor="#673AB7"
        android:textSize="36sp"
        android:typeface="normal" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="vertical">

        <Button
            android:id="@+id/button"
            android:layout_width="171dp"
            android:layout_height="55dp"
            android:text="@string/alphabetButton" />

        <Button
            android:id="@+id/button2"
            android:layout_width="171dp"
            android:layout_height="55dp"
            android:text="@string/alphabetButton" />

        <Button
            android:id="@+id/button3"
            android:layout_width="171dp"
            android:layout_height="55dp"
            android:text="@string/alphabetButton" />
    </LinearLayout>


</RelativeLayout>

输出


如果您想将按钮置于屏幕中央,只需使用android:layout\u centerInParent=“true”

用这个

<Button
        android:id="@+id/button"
        android:layout_width="171dp"
        android:layout_height="55dp"
        android:layout_centerInParent="true"
        android:text="alphabetButton" />

而不是这个

<Button
        android:id="@+id/button"
        android:layout_width="171dp"
        android:layout_height="55dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:layout_marginStart="119dp"
        android:layout_marginLeft="119dp"
        android:layout_marginTop="186dp"
        android:layout_marginEnd="121dp"
        android:layout_marginRight="121dp"
        android:layout_marginBottom="362dp"
        android:text="@string/alphabetButton" />

示例代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:lineSpacingExtra="8sp"
        android:text="@string/selamatDatang"
        android:textColor="#673AB7"
        android:textSize="36sp"
        android:typeface="normal" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="vertical">

        <Button
            android:id="@+id/button"
            android:layout_width="171dp"
            android:layout_height="55dp"
            android:text="@string/alphabetButton" />

        <Button
            android:id="@+id/button2"
            android:layout_width="171dp"
            android:layout_height="55dp"
            android:text="@string/alphabetButton" />

        <Button
            android:id="@+id/button3"
            android:layout_width="171dp"
            android:layout_height="55dp"
            android:text="@string/alphabetButton" />
    </LinearLayout>


</RelativeLayout>

输出


我复制了你的按钮,它在我的屏幕上正常显示。。。但是我用了这个:

android:text=“alphabetButton”

与此相反:


android:text=“@string/alphabetButton”
我复制了你的按钮,它在我的屏幕上正常显示。。。但是我用了这个:

android:text=“alphabetButton”

与此相反:


android:text=“@string/alphabetButton”

请与共享您的整个布局文件question@NileshRathod更新请与共享您的整个布局文件question@NileshRathodupdatedno我不想让它成为中心,如果它能工作,那么我还有其他按钮要添加。我只需要在中间上方显示一点,每个按钮下面有3个按钮other@mafortis可以将您的预期输出与问题共享,这样我就可以将我的答案更新为与您的屏幕截图相同的内容,在下面添加两个距离相同的按钮,并将所有3个按钮都向上拉一点。因此,一般来说,其中3个将处于中心位置screen@mafortis欢迎让我知道如果你有任何queryno我不想让它成为中心,如果它工作,那么我有其他按钮添加。我只需要在中间上方显示一点,每个按钮下面有3个按钮other@mafortis可以将您的预期输出与问题共享,这样我就可以将我的答案更新为与您的屏幕截图相同的内容,在下面添加两个距离相同的按钮,并将所有3个按钮都向上拉一点。因此,一般来说,其中3个将处于中心位置screen@mafortis欢迎让我知道如果你有任何疑问,我需要使用字符串有两个原因:1)避免工作室警告2)使用翻译,所以我真的不认为使用字符串是这里的问题。感谢btwhi,我需要使用字符串有两个原因:1)避免studio警告2)使用翻译,所以我真的不认为使用字符串是这里的问题。谢谢,顺便说一句