2

我有一个垂直的 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 会扩展整个屏幕宽度和系统启动拨号器。

4

1 回答 1

1

您是否尝试过像这样以编程方式设置参数:

myTextView.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

并删除

android:layout_weight="0"

这里哪个没用?

于 2012-10-24T13:03:36.400 回答