java - 三星 J5 中的 Android Textview settext 问题

标签 java android eclipse textview settext

我的应用程序出现“问题”,但我不知道发生了什么。

我有这个界面:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="1dp"
    android:orientation="vertical" >

   <Button
       android:layout_width="fill_parent"
       android:layout_height="50dp"
       android:background="@color/white"
       android:gravity="center"
       android:textColor="@color/black" />

   <TextView
       android:id="@+id/detailServiceTxtPhone"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_gravity="center"
       android:layout_marginTop="-35dp"
       android:ellipsize="end"
       android:gravity="center"
       android:maxLength="50"
       android:singleLine="true"
       android:textColor="@color/black" />

</LinearLayout>

我从 Web 服务获取字段值并在 Java 代码中设置文本:

m_txtPhone.setText(m_currentService.PassengerPhone);

在我检查的所有设备中,结果如下: 12345678

但我在使用 Samsung J5 (5.1.1) 时遇到问题。当我尝试在 TextView (和类似的)中设置文本时,我得到以下结果:

Empty view

似乎我在设置文本时遇到了一些问题或者我不知道。有什么想法吗?

注意: 我以这种方式实现接口(interface),因为在其他情况下我会这样做:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="1dp"
    android:orientation="vertical" >

    <Button
        android:id="@+id/detailServiceBtnClient"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        android:background="@color/white"
        android:drawableRight="@drawable/icon_detail"
        android:gravity="left|center_vertical"
        android:paddingLeft="5dp"
        android:paddingRight="5dp"
        android:text="@string/detailServiceBtnClient"
        android:textColor="@color/black" />

    <TextView
        android:id="@+id/detailServiceTxtClient"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_marginRight="25dp"
        android:layout_marginTop="-35dp"
        android:ellipsize="end"
        android:gravity="center"
        android:maxLength="50"
        android:singleLine="true"
        android:textColor="@color/black" />

</LinearLayout>

Cliente<--->aRTyMaNYa

最佳答案

您正在使用 LinearLayout。在此布局中,项目添加在每个元素之后。您的方向是垂直的,因此它位于按钮下方。使用RelativeLayout,然后使用TextView的alignTop和alignBottom属性。

android:alignTop="@+id/button"
android:alignBottom="@+id/button"
android:gravity="center"

关于java - 三星 J5 中的 Android Textview settext 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34674918/

相关文章:

java - Android + RxJava + For Loop + 不执行所有请求

java - Libvirt Java 绑定(bind) - 在 Xen 中使用 listDomains()

android - 媒体播放器 : How to update progress every second?

Android 动态壁纸 - 不显示背景图片?

java - 问题是针对 eclipse javaEE 版本。该项目未构建,因为其构建路径不完整

Ubuntu 中的 Eclipse 无法启动,退出时没有任何错误代码

java - 如何使用 HTTP/2 over TLS 发送 HTTP 请求? (Java 11 HttpClient)

java - hibernate中的依赖事务

android - 如何查询屏幕固定设置?

java - JFileChooser showOpenDialog 方法不适用于 ActionListener