我有一个垂直的 LinearLayout 和 TextView。
文件:unitdetails.xml
<LinearLayout
android:id="@+id/unit_details_person"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/unit_person_header"
android:orientation="vertical" />
文件:person_phone.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="0"
android:background="@android:color/darker_gray"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:paddingLeft="15dp"
android:text="Some text">
</TextView>
我在我的活动代码中添加了 TextView
while (iterator.hasNext()) {
Person person = iterator.next();
TextView positionTV = (TextView) getLayoutInflater().inflate(R.layout.person_position, null);
TextView personTV = (TextView) getLayoutInflater().inflate(R.layout.person_person, null);
TextView phoneTV = (TextView) getLayoutInflater().inflate(R.layout.person_phone, null);
TextView emailTV = (TextView) getLayoutInflater().inflate(R.layout.person_email, null);
positionTV.setText(person.getPosition());
personTV.setText(person.getPerson());
phoneTV.setText(person.getPhone());
emailTV.setText(person.getEmail());
Linkify.addLinks(phoneTV, Linkify.PHONE_NUMBERS);
Linkify.addLinks(emailTV, Linkify.EMAIL_ADDRESSES);
personLinearLayout.addView(positionTV);
personLinearLayout.addView(personTV);
personLinearLayout.addView(phoneTV);
personLinearLayout.addView(emailTV);
}
添加后,当我单击电话号码的右侧时,TextView 会扩展整个屏幕宽度和系统启动拨号器。