我遇到了android只支持用2行省略TextView的问题。我在这里找到了解决方案android ellipsize multiline textview
但是我现在我的文本视图显示得很奇怪,所以不是:
This is a test...
我的 TextView 显示
This
is
a
此外,EllipsizingTextView 似乎会影响同一布局中的另一个 TextView,该布局尚未被声明为 EllipsizingTextView,而是常规的 TextView。无论如何,这是有问题的代码:
@Override
public View getView(int position, View itemView, ViewGroup parent) {
View v = itemView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_item, null);
LinearLayout layout = (LinearLayout) v.findViewById(R.id.linearLayout1);
EllipsizingTextView desc = new EllipsizingTextView(parent.getContext());
desc.setMaxLines(3);
layout.addView(desc);
ViewHolder vh = new ViewHolder();
vh.label = (TextView) v.findViewById(R.id.label);
vh.img = (ImageView) v.findViewById(R.id.img);
vh.desc = (EllipsizingTextView) desc;
vh.dateAdded = (TextView) v.findViewById(R.id.tvDateAdded);
v.setTag(vh);
}
和 XML:
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="0px"
android:orientation="vertical" >
<TextView android:text="@+id/TextView01" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/label"
android:textSize="16sp" android:gravity="center_vertical" android:textColor="#000" android:singleLine="true"
/>
<TextView
android:id="@+id/tvDateAdded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:textSize="13sp"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>