¿Cómo crear Scrollview mediante programación?

Tengo una tabla "TABLE_SUBJECT" que contiene una serie de temas. Necesito crear
Una vista de desplazamiento horizontal con Asunto.

¿Cómo puedo crear un ScrollView con elementos de base de datos mediante programación? Si ingreso 1o tema, entonces aparecerá en la vista de desplazamiento como un botón. ¿Es posible?

Usted puede crearlo como abajo:

ScrollView scroll = new ScrollView(context); scroll.setBackgroundColor(android.R.color.transparent); scroll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); scroll.addView(yourTableView); 

Esto puede ayudarle.

  HorizontalScrollView hsrll = (HorizontalScrollView)findViewById(R.id.hrsll); b = new Button(this); for (int i = 0; i < 5; i++) { b.setWidth(LayoutParams.WRAP_CONTENT); b.setHeight(LayoutParams.WRAP_CONTENT); b.setText("b"+i); b.setId(100+i); hsrll.addView(b); } 

En vez de para el lazo apenas modifica el código como su necesidad (ninguÌ n registro en db). Pero este es el código para crear botones en forma dinámica.

Si tiene muchos elementos primero tiene que terminar y agregar en la vista de desplazamiento; Por ejemplo, necesito una vista de muchos textos dentro de scrollview, por lo que necesitas crear ScrollView-> LinearLayout-> Many textview

  ScrollView scrollView = new ScrollView(context); scrollView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); TextView textView = new TextView(context); textView.setText("my text"); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setGravity(Gravity.RIGHT); linearLayout.addView(textView); scrollView.addView(linearLayout); 

Lo estaba haciendo así:

  • Crear xml con LinearLayout dentro de ScrollView
  • Crear xml como elemento en ScrollView
  • En el contenido principal de conjunto de actividades como xml con ScrollView
  • Bucle a través de todos los elementos de la tabla con la adición de nuevo Ver a LinearLayout vista principal del formulario

Para mí funciona bien.

  • ¿Por qué el teclado virtual muestra o no cuando se inicia una actividad?
  • Centro de contenido en vista de desplazamiento
  • Espacio en blanco se agrega al final cuando pongo Webview dentro de scrollview en android
  • No estirar ScrollView
  • Android Scrollview en RelativeLayout con ButtonBar
  • ViewPager en un Layout detrás de un ScrollView sin escuchar gestos
  • Cómo crear un número variable de vistas de texto en android
  • ¿Por qué mi ScrollView es demasiado ancha sólo cuando no necesita desplazarse?
  • Android: cómo hacer scrollview infinito con desplazamiento sin fin
  • Android ScrollView establece la altura del contenido visualizado
  • Cómo agregar ScrollView a GLSurfaceview en Opengl ES2.0 en Android
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.