【发布时间】: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