Android TextView未在TableRow内的LinearLayout中省略号
我已尝试将我的TextView省略(它们位于TableRow内的LinearLayout中),但是,除非我手动设置maxEms(我不想这样做),否则它们无法正确省略。注意:整个xml(除了TableLayout)是通过编程生成的 我已经尝试了大多数修复:搞乱布局参数(有点),将setMaxLines更改为setSingleLine,还有其他修复,但如果答案就在眼前,我还是要道歉 生成代码:Android TextView未在TableRow内的LinearLayout中省略号,android,android-layout,Android,Android Layout,我已尝试将我的TextView省略(它们位于TableRow内的LinearLayout中),但是,除非我手动设置maxEms(我不想这样做),否则它们无法正确省略。注意:整个xml(除了TableLayout)是通过编程生成的 我已经尝试了大多数修复:搞乱布局参数(有点),将setMaxLines更改为setSingleLine,还有其他修复,但如果答案就在眼前,我还是要道歉 生成代码: TableLayout tableLayout = (TableLayout) view.findView
TableLayout tableLayout = (TableLayout) view.findViewById(R.id.table);
// Add text
for (int iter=0;iter<DisplayJson.summaryData.tasks.length;iter++) {
TableRow tableRow = new TableRow(this);
tableRow.setPadding(16,16,16,16);
LinearLayout container = new LinearLayout(this);
container.setOrientation(LinearLayout.VERTICAL);
TableLayout.LayoutParams rowParams = new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT);
TableRow.LayoutParams layoutLayoutParams = new TableRow.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
1.0f);
TextView titleView = new TextView(this);
titleView.setText(DisplayJson.summaryData.tasks[iter].get("title"));
titleView.setEllipsize(TextUtils.TruncateAt.END);
titleView.setMaxLines(1);
//titleView.setMaxEms(22); I do NOT want to set this (but setting it DOES work as expected)
titleView.setLayoutParams(layoutParams);
TextView classView = new TextView(this);
classView.setText(DisplayJson.summaryData.tasks[iter].get("class"));
classView.setLayoutParams(layoutParams);
container.addView(titleView);
container.addView(classView);
container.setLayoutParams(layoutLayoutParams);
tableRow.addView(container);
setOnClick(tableRow, iter); //Custom function which does not affect the problem
tableRow.setLayoutParams(rowParams);
tableLayout.addView(tableRow);
}
setContentView(view);
TableLayout TableLayout=(TableLayout)view.findviewbyd(R.id.table);
//添加文本
对于(int-iter=0;iter如果您在Android Studio中查看布局检查器的输出,您将看到您的标题视图
正在放大表格行的宽度。更改线性布局的布局参数以赋予其权重,如下所示,您将看到省略号出现:
TableRow.LayoutParams layoutLayoutParams = new TableRow.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
1.0f);
我希望这能有所帮助。谢谢!我本该自己解决的,但不管怎样,你让我开心了!
TableRow.LayoutParams layoutLayoutParams = new TableRow.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT,
1.0f);