2017-12-31 108 views
0

Hier mein Code istLinearlayout in einem Scrollview zeigt nicht

mainView = new MainView(this, imageId, text, 3); 
mainView.setOnTouchListener(this); 
LinearLayout.LayoutParams mainParams = new 
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
LinearLayout mainLinear = new LinearLayout(this); 
ScrollView.LayoutParams scrollParams = new 
ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
ScrollView scrollView = new ScrollView(this); 
LinearLayout.LayoutParams myViewParams = new 
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
mainLinear.addView(mainView, myViewParams); 

scrollView.addView(mainLinear, mainParams); 
addContentView(scrollView, scrollParams); 

Natürlich ist es nur innerhalb LinearLayout funktioniert. Bitte sagen Sie mir, wie man es in eine ScrollView steckt.

+0

Sie können versuchen, die 'mit einer Größe von' WRAP_CONTENT' statt 'MATCH_PARENT' LinearLayout'. Und (nicht verwandt) warum machst du das in Java und nicht in XML? – Henry

+0

Wirst du einen Unfall bekommen? – lib4

+0

Henry << Ich mache eine ansprechende Ansicht mit Java. Es ist aber die Schriftrolle fertig. Tatsächlich kann ich den Bildlauf durchführen, indem ich OnTouchListener implementiere, und dann die 2 Y-Achsenpunkte ACTION_DOWN und ACTION_MOVE ermitteln, um festzustellen, ob der Benutzer einen Ziehvorgang ausführt. Aber ich habe versucht, was du mir gesagt hast. Aber es hat noch nicht funktioniert! –

Antwort

0

ScrollView 's Kind sollte nur Höhe wie WRAP_CONTENT haben. Wenn Sie das gleiche Layout mit xml AS versuchen, erhalten Sie eine Flusenwarnung, die genau das sagt.

Wenn Ihre Kinderansicht die volle Höhe der Bildlaufansicht einnehmen muss, wenn der Inhalt weniger ist, können Sie setFillViewport() verwenden.

Dies sollte für Sie arbeiten:

mainView = new MainView(this, imageId, text, 3); 
mainView.setOnTouchListener(this); 
LinearLayout.LayoutParams mainParams = new 
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 
LinearLayout mainLinear = new LinearLayout(this); 
ScrollView.LayoutParams scrollParams = new 
ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
ScrollView scrollView = new ScrollView(this); 
LinearLayout.LayoutParams myViewParams = new 
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
mainLinear.addView(mainView, myViewParams); 

scrollView.addView(mainLinear, mainParams); 
scrollView.setFillViewport(true); 
addContentView(scrollView, scrollParams); 
Verwandte Themen