android似乎无缘无故地切断了我的文本视图。
围绕该区域的XML是:
<HorizontalScrollView
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:color/background_dark"
android:layout_width="fill_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:id="@+id/suggestions">
</LinearLayout>
</HorizontalScrollView>
我正在以编程方式添加TextViews,如下所示:
LinearLayout suggestions = (LinearLayout)findViewById(R.id.suggestions);
suggestions.setVisibility(View.VISIBLE);
suggestions.removeAllViews();
for(String completion : completions){
TextView show = new TextView(DailyboothBoothView.this);
show.setTag(completion + " ");
show.setText("@" + completion);
show.setPadding(5, 5, 5, 5);
show.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// Some code here
}
});
show.setHeight(show.getLineHeight() + 10);
show.setTextColor(Color.parseColor("#cc6600"));
suggestions.addView(show);
}
答案 0 :(得分:2)
让视图执行测量并删除show.setHeight(show.getLineHeight() + 10)
。看起来TextView在第一行文本之前有一些内部额外的填充,你没有考虑到这一点。
答案 1 :(得分:1)
尝试更换:
suggestions.addView(show);
使用:
suggestions.addView(show, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));