1
我使用下面的代码到多个TextViews添加到CommonsWare ViewSwiper但我看到重叠TextViews:添加多个视图ViewSwiper动态
for (int i = 0; i < 10; i++){
LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.c_layout, null);
// fill in any details dynamically here
TextView textView = (TextView) v.findViewById(R.id.myTextView);
textView.setText("This is text " + i);
swiper.addView(textView);
}
以下为c_layout.xml布局:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
这应该是什么正确的做法。