/ / Android Programmatic Popup ScrollView TextView - Android, layout Android

Popolarità programmatica Android ScrollView TextView - android, android-layout

Cosa c'è di sbagliato con questo codice?

Mostra solo la finestra popup grigia, non appare ScrollView o TextView.

Tuttavia, se aggiungo il pulsante indicato dal ramo falso, viene visualizzato il pulsante.

Qui sto aggiungendo più testo, perché SO non mi consente di pubblicare senza più testo.

Grazie!

static PopupWindow DebugScreen( Activity a )
{
final PopupWindow popUp = new PopupWindow( a );

final View cv = a.getWindow().getDecorView().findViewById( android.R.id.content );

FrameLayout.LayoutParams p = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.TOP );
FrameLayout fl = new FrameLayout( a );
fl.setLayoutParams(p);

final ScrollView sv = new ScrollView( a );
final TextView tv = new TextView( a );

LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (cv.getHeight() * 0.9), Gravity.TOP);

tv.setText("Hello World");
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setLayoutParams( lp );

sv.addView(tv, lp);

if ( false ) {
final Button b;
b = new Button(a);
b.setText("abc123");
b.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
fl.addView(b);
}

popUp.setContentView(fl);

popUp.showAtLocation(cv, Gravity.BOTTOM, 0, 0);
popUp.setFocusable(false);
popUp.setOutsideTouchable(true);
popUp.setTouchable(true);

popUp.setTouchInterceptor(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if ( event.getAction() == MotionEvent.ACTION_OUTSIDE) {
popUp.dismiss();
return true;
}
return false;
}
});
popUp.update( 0, 0, (int) (cv.getWidth() * 0.9), cv.getHeight() );
return( popUp );
}

risposte:

0 per risposta № 1

Ti sei perso fl.addView(sv); per aggiungere ScrollView a FrameLayout. Aggiungilo prima popUp.setContentView(fl); per vedere TextView.