【问题标题】:EditText appears in Design but not in the real apkEditText 出现在设计中,但没有出现在真正的 apk 中
【发布时间】:2019-04-18 03:55:18
【问题描述】:

这是activity_main.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"
>

<TextView
    android:id="@+id/label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Text:"
   />

<EditText
    android:layout_toRightOf="@id/label"
    android:layout_toEndOf="@id/label"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="text"
    android:hint="type ur text here"
    android:layout_alignBaseline="@id/label"

    />
</RelativeLayout>

在设计中,在 Android Studio 上,TextViewEditText 都可以看到,但编译后只有 TextView 是可见的。

为什么?

截图

设计:

Apk:

谢谢

样式.xml:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

</resources>

【问题讨论】:

  • 你能把截图也发一下吗
  • 尝试更改样式文件中的主题。您可以在这里分享您的样式文件代码,以便我为您提供帮助。
  • android:layout_alignBaseline="@id/label"改为android:layout_alignBaseline="@+id/label"android:layout_toRightOf="@id/label"改为android:layout_toRightOf="@+id/label"android:layout_toEndOf="@id/label" toandroid:layout_toEndOf="@+id/label"
  • 删除android:layout_alignBaseline="@id/label"
  • 复制粘贴您的代码并运行应用程序。它就像一个魅力。也许你还有其他问题。尝试在任何其他设备上测试它

标签: android android-studio android-layout android-edittext


【解决方案1】:

试试这个代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:orientation="horizontal"
    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"
    >

    <TextView
        android:id="@+id/label"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Text:"
        />

    <EditText
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:hint="type ur text here"
        />
</LinearLayout

【讨论】:

  • Thks,但我必须使用 RelativeLayout
  • 可能是你用过的风格
  • 换个样式试试
  • 相同结果,移除 alignBaseline 使 EditText 可见,但不是预期结果
  • 我试过你的代码,它对我有用。您使用的是哪种设备?
猜你喜欢
  • 1970-01-01
  • 2011-05-01
  • 2014-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-25
  • 2021-06-05
  • 1970-01-01
相关资源
最近更新 更多