我的应用程序出现“问题”,但我不知道发生了什么。
我有这个界面:
<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
(和类似的)中设置文本时,我得到以下结果:
似乎我在设置文本时遇到了一些问题或者我不知道。有什么想法吗?
注意: 我以这种方式实现接口(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>
最佳答案
您正在使用 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/