i want to add some TextView to a Vertical LinearLayout programmatically. but there is a strange problem: when i set a Drawable to these TextViews(using setBackgroundDrawable() method) and add them to LinearLayout programmatically the TextView's Drawable does not show correctly.
this only happen when i have more than one TextView, if there is one the Background Drawable show correctly.
also this only happen when i add TextView programmatically, in the case that i add some TextView in XML Drawable is fine.
My codes:
rootView = inflater.inflate(R.layout.fragment, container, false);
linearLinear = (LinearLayout) rootView.findViewById(R.id.ll);
Drawable mDrawable =getActivity().getResources().getDrawable(R.drawable.textview_drawable);
TextView mTextView;
for(int i =0;i<textViewCount;i++)
{
mTextView = new TextView(context);
mTextView.setText(mText.get(i));
mTextView .setBackgroundDrawable(mDrawable);
linearLinear.addView(mTextView);
}
XML Drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<solid android:color="#ffddf978" />
<corners
android:radius="9dp"
/>
<stroke
android:width="1dp"
android:color="#D7D7D7" />
</shape>
for some reason the first TextView's Drawable is not correct but the second is fine. i take some image from my device screen:
http://i61.tinypic.com/1zd5cu9.png
http://i58.tinypic.com/2nby79e.png
please help me!
sorry for bad English.