0
我遇到了這個問題,即android只支持用兩行來橢圓化TextView。我發現這裏的解決方案android ellipsize multiline textview將一個自定義的EllipsizingTextView添加到佈局
但是我現在我的textviews越來越奇怪的顯示,所以不是:
This is a test...
我的TextView dispalys
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>