0

내 코드가 잘 컴파일되고, Activity를 시작하면 관련 레이아웃이 표시되지만 이후 onCreate()에서 동적으로 작성한 위젯은 표시되지 않습니다.내 동적으로 생성 된 위젯이 표시되지 않습니다.

왜 그렇습니까?

Eclipse는 Debug Perspective에 포함되지 않으며 단순히 표시되지 않습니다.

다음은 관련 코드입니다 :

public class Authorize_Activity_DynamicControls extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.ondemandandautomatic_dynamicauthorize); 

     LinearLayout llay = new LinearLayout(this); 
     llay.setOrientation(LinearLayout.HORIZONTAL); 

     LinearLayout.LayoutParams llp = new LayoutParams(LayoutParams.WRAP_CONTENT,  
LayoutParams.WRAP_CONTENT); 
     llp.weight = 1.0f; 

     CheckBox cb = new CheckBox(getApplicationContext()); 
     cb.setText("1"); 
     cb.setLayoutParams(llp); 
     llay.addView(cb); 

     ScrollView svh = (ScrollView) findViewById(R.id.scrollViewHost); 
     svh.addView(llay); 
    } 

... 여기 레이아웃 XML입니다 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" >  

     <TextView 
      android:id="@+id/textView1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="2dip" 
      android:text="@string/demand" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 

     <TextView 
      android:id="@+id/textView2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="2dip" 
      android:text="@string/time" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 

     <TextView 
      android:id="@+id/textView3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="2dip" 
      android:text="@string/space" 
      android:textAppearance="?android:attr/textAppearanceSmall" /> 

     <TextView 
      android:id="@+id/textView4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="2dip" 
      android:text="@string/contact" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

    <ScrollView 
     android:id="@+id/scrollViewHost" 
     android:fillViewport="true" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" > 

    </ScrollView> 

</LinearLayout> 

답변

1

당신이 원하는 결과를 얻기 위해 수동으로 전체보기를 무효화해야하므로 추가 시도 할 수 있습니다 이 줄 끝까지 :

svh.invalidate(); 
+0

invalidate()를 추가해도 도움이되지 않았지만 아무 것도 해를 끼치 지 않는다고 생각합니다. 그래서 지금은 거기에 앉아 있습니다. –

+0

시도해 볼 수 있습니까? xml 파일의 자식 LinearLayout 섹션을 제거하여 ScrollView가 기본 LinearLayout의 유일한 자식이되도록 할 수 있으며 동적으로 추가 한 LinearLayout과 함께 ScrollView를 볼 수 있는지 확인하십시오. – Soham

+0

OK, 감사합니다, Soham, 도움이됩니다 - 이제 동적으로 추가 된 위젯이 표시됩니다. 그러나 동적으로 추가 된 위젯은 xml에 선언 된 위젯과 동일한 "행"으로 표시되며 xml에 선언 된 위젯 아래에 자신의 "행"에 있어야합니다. 어떻게 강제로 그렇게 할 수 있습니까? –

1

onCreate()에서 추가 한보기를 무효화 할 필요는 없습니다. XML 레이아웃 파일을 사용하지 않고도 자신있게 게시물에 답변하려고하는 것은 당연한 일입니다. 체크 박스 대신 TextView를 사용해 보셨습니까?

+0

확인란이 필요합니다. –

+0

레이아웃 파일을 원래 게시물에 추가했습니다. 그것은 잘 렌더링됩니다 - 그것은 동적으로 추가 된 것들이 표시되지 않습니다. –

관련 문제