我在StackOverflow的任何地方查找它並且似乎無法找到我的問題的答案。下面提供了我正在運行API v.16設備,以及使用Drawable作爲背景的TextView的後臺更新方法。其他的工作 - TextViews成功改變了它們的textSize和height/width,在這裏未提到的部分代碼。任何想法可能是什麼問題?該應用程序不會停止,只有中風的厚度沒有變化。實際上,TextView完全放棄了其背景。它的原始背景是一個特定筆畫寬度的角平滑矩形,它的大小和筆畫寬度應該減半。更改後沒有背景在TextView中一起顯示。設置可以繪製到TextView的背景不起作用
if (textViewsArrayList.size() != 0) textViews.get(textViewsArrayList.size() - 1).post(new Runnable() {
@Override
public void run() {
for (counter = 0; counter < textViewsArrayList.size(); counter++) {
textViewsArrayList.get(counter).getLayoutParams().height = (int)
(textViewsArrayList.get(counter).getLayoutParams().height/2);
textViewsArrayList.get(counter).getLayoutParams().width = (int) (textViewsArrayList.get(counter).getLayoutParams().width/2);
((TextView) textViewsArrayList.get(counter)).setTextSize(TypedValue.COMPLEX_UNIT_PX, (int) (((TextView) textViewsArrayList.get(counter)).getTextSize()/2));
GradientDrawable background = (GradientDrawable) textViewsArrayList.get(counter).getBackground();
background.setStroke((int) (4/displayMetrics.density/2), (int) Color.parseColor("#FFA500"));;
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
((TextView) textViewsArrayList.get(counter)).setBackground((Drawable) background);
} else {
((TextView) textViewsArrayList.get(counter)).setBackgroundDrawable((Drawable) background);
}
}
}
});
雖然有問題的TextView中的XML是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="320dp"
android:layout_height="90dp"
android:tag="layout">
<TextView
android:id="@+id/textview"
android:layout_height="68dp"
android:layout_width="match_parent"
android:background="@drawable/drawable_xml"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="7dp"
android:tag="textview_in question"/>
etc.
至於提拉XML:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="4dp"
android:color="#FF6600" />
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
<solid android:color="#FFFFFF" />
</shape>
從您的xml中刪除android:background =「@ drawable/drawable_xml」 。只從java代碼 – Anjali
設置背景嘿,當我檢查你的代碼時,你的代碼是完美的,我也回答了你的問題。 –
@ Anjali:試過了,但沒有奏效。不管怎麼說,還是要謝謝你。 – Dmitri