动态添加多个视图到ViewSwiper
我使用以下代码将多个 TextView 添加到 CommonsWare ViewSwiper,但我看到重叠 TextView:
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" />
执行此操作的正确方法应该是什么。
I am using the following code to add multiple TextViews to CommonsWare ViewSwiper but I see Overlapping TextViews:
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);
}
Following is the layout for 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" />
what should be the proper way of doing this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用以下代码使其正常工作,以防其他人需要帮助:
Used the following code to get it to work, In case someone else needs help: