내 코드가 잘 컴파일되고, 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>
invalidate()를 추가해도 도움이되지 않았지만 아무 것도 해를 끼치 지 않는다고 생각합니다. 그래서 지금은 거기에 앉아 있습니다. –
시도해 볼 수 있습니까? xml 파일의 자식 LinearLayout 섹션을 제거하여 ScrollView가 기본 LinearLayout의 유일한 자식이되도록 할 수 있으며 동적으로 추가 한 LinearLayout과 함께 ScrollView를 볼 수 있는지 확인하십시오. – Soham
OK, 감사합니다, Soham, 도움이됩니다 - 이제 동적으로 추가 된 위젯이 표시됩니다. 그러나 동적으로 추가 된 위젯은 xml에 선언 된 위젯과 동일한 "행"으로 표시되며 xml에 선언 된 위젯 아래에 자신의 "행"에 있어야합니다. 어떻게 강제로 그렇게 할 수 있습니까? –