【问题标题】:Android Textview settext issue in Samsung J5三星 J5 中的 Android Textview settext 问题
【发布时间】:2016-01-08 10:37:17
【问题描述】:

我的应用程序有一个“问题”,我不知道发生了什么。

我有这个界面:

<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);

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

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

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

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

<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>

【问题讨论】:

  • 为什么要向我们展示 xml ?我们需要代码来理解“m_currentService.PassengerPhone”
  • 对不起。 “m_currentService”是具有定义服务的所有属性的对象。这些属性是电话、代码、状态、日期时间创建等。我用 Web 服务响应填充这个属性,我确定这些属性已填充,但仅在三星 Galaxy J5 中,当我执行 textview.setText 时,文本为空白.
  • 您确定这些属性已填充。请尝试 setText("Test") 所以
  • setText 它适用于我所有的设备,除了三星 Galaxy J5。我可以尝试三星 Galaxy S4 和 S5 和 S6、BQ Aquaris E5、三星 Galaxy Tab 1 和 3,但 J5 是唯一一个它不工作的jajaja。我怀疑它是否是marginTop -35 ...

标签: java android eclipse textview settext


【解决方案1】:

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

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

【讨论】:

  • 谢谢凯沙夫。我尝试了它,结果是一样的,不显示任何文本...我将 LinearLayout 修改为 RelativeLayout 并在 textview xml 代码中添加 layout_alignTop/Bottom。
  • 删除TextView中的marginTop
  • 它也被删除了。如果我将 textview 放在按钮之前,则会出现文本,但文本是粗体的,我没有放置这种样式...
猜你喜欢
  • 1970-01-01
  • 2019-04-14
  • 1970-01-01
  • 2020-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多