Pri*_*alj 1 android android-layout android-button
前 5 个按钮以编程方式添加,最后一个按钮通过 XML 添加。两种方式我都使用相同的参数。为什么动态添加的按钮文本会被截断?
程序化:
Button b = new Button(getActivity());
b.setText(text);
b.setAllCaps(false);
b.setBackgroundResource(R.drawable.button_tag_rect);
b.setTextColor(getResources().getColor(R.color.colorWhiteText));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
dpToPx(28));
int marginInPx = dpToPx(2);
params.setMargins(marginInPx, marginInPx, marginInPx, marginInPx);
tagCloudTwitter.addView(b, tagCloudTwitter.getChildCount()-1, params);
Run Code Online (Sandbox Code Playgroud)
XML:
<Button
android:layout_width="wrap_content"
android:layout_height="28dp"
android:layout_margin="2dp"
android:textAllCaps="false"
android:background="@drawable/button_tag_rect"
android:textColor="@color/colorWhiteText"
android:text="test"/>
Run Code Online (Sandbox Code Playgroud)
编辑:解决了!请参阅下面我的回答。
有趣的是,有帮助的是设置一个“虚拟”填充:
\n\nb.setPadding(1,1,1,1);\nRun Code Online (Sandbox Code Playgroud)\n\n\xc2\xaf\\_(\xe3\x83\x84)_/\xc2\xaf
\n