我想在我的ListView
适配器中制作一个有点复杂的布局。
列表中的每个项目由 4 个组合而成TextView
前三个TextView
基本上是一个句子,但我希望第二个TextView
不要被省略,第一个和第三个我确实想要被省略。
最后一个TextView
需要定位在右侧。
所以如果前三个TextView
不能完全显示,布局应该是这样的:
`TextView1...` `TextView2` `TextView3...` `TextView4`
我的代码在这种情况下工作,但在简单的情况下,当不需要椭圆大小时,它不需要,它看起来像这样:
`TextView1` `TextView2` `TextView3` `TextView4`
这是我的代码:
LinearLayout layout = new LinearLayout(m_context);
layout.setGravity(Gravity.CENTER_VERTICAL);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setLayoutParams(new ListView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
LinearLayout textLayout = new LinearLayout(m_context);
textLayout.setOrientation(LinearLayout.HORIZONTAL);
textLayout.setGravity(Gravity.CENTER_VERTICAL);
view.m_text1 = new TQTextView(m_context);
view.m_text1.setSingleLine();
view.m_text1.setEllipsize(TruncateAt.END);
view.m_text2 = new TQTextView(m_context);
view.m_text3 = new TQTextView(m_context);
view.m_text3.setSingleLine();
view.m_text3.setEllipsize(TruncateAt.END);
view.m_text1 = new TQTextView(m_context);
textLayout.setWeightSum(2f);
textLayout.addView(view.m_text1, new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f));
textLayout.addView(view.m_text2, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0f));
textLayout.addView(view.m_text3, new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f));
layout.addView(textLayout, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1f));
view.m_text4 = new TQTextView(m_context);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0f);
int margin = 10;
params.leftMargin = margin;
params.gravity = Gravity.CENTER_VERTICAL|Gravity.RIGHT;
layout.addView(view.m_text4, params);