Добавление нескольких видов в ViewSwiper динамически

1

Я использую следующий код, чтобы добавить несколько TextViews в CommonsWare ViewSwiper, но я вижу 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);

    }

Ниже приведен макет для 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" />

что должно быть правильным способом сделать это.

Теги:
commonsware-cwac

1 ответ

0
Лучший ответ

Используется следующий код, чтобы заставить его работать, если кому-то нужна помощь:

    ViewSwiper swiper = (ViewSwiper)findViewById(R.id.swiper); 

    ViewFlipper flipper = swiper.getFlipper();

    for (int i = 0; i < 10; i++){

        LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = vi.inflate(R.layout.trivia_text, null);

        // fill in any details dynamically here
        TextView textView = (TextView) v.findViewById(R.id.triviaText);
        textView.setId(i);
        textView.setText("This is text " + i);

        flipper.addView(textView);

    }

Ещё вопросы

Сообщество Overcoder
Наверх
Меню