아마 모든 게시물과 문서를 읽었지만 여전히이 문제를 해결할 수 없습니다.addView가 작동하지 않습니다.
기존의 (실행중인) 레이아웃에보기를 추가하려면 addView() 메소드를 사용하고 싶지만 어떤 이유로 든 위선적으로 말합니다. 나는 이것이 쉽고 기본적인 것이어야하지만 아직도 그것을 할 수 없다는 것을 안다. 그래서 제발 도와주세요. 여기
는 코드입니다LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
TextView text=new TextView(this);
text.setText("test");
layout.addView(text);
코드, 그리고 결과는 내가 XML 파일에 정의되어 있습니다 만 뷰를 표시 한 것입니다. 내가 추가 한이 새로운 견해가 없습니다. 디버깅 할 때이 추가 된보기를 추가 한 부모의 자식으로 표시되지만 표시되지는 않습니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/main1" >
<TextView android:id="@+id/app_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:text="@string/app_title"
android:textSize="25dp"
android:gravity="center_horizontal"/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="@string/main_screen_counter_title"
android:textSize="15dp"
android:textColor="#FFF"
android:gravity="center_horizontal"/>
<TextView android:id="@+id/frontScreenCounter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:text="@string/reading"
android:textSize="33dp"
android:gravity="center_horizontal" />
<GridView android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="3"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:textColor="#888"
/>
</LinearLayout>
이 도와주세요 : 여기
는 main.xml에 있습니다. 이것은 나를 미치게 할 것이다!
'TextView'를 추가 할 레이아웃을 추가 할 수 있습니까? – Luksprog
Hey Luksprog, 왜냐하면 android : layout_height = "fill_parent"가 LinearLayout 속성에 있기 때문입니다. 이제 텍스트가 표시되었지만 화면의 맨 아래에 있습니다. 그것을 맨 위에 올려 놓는 방법? 당신이 나를 도왔습니다. 간접적이지만 여전히. Tnx 많이. – Majstor
그 'TextView'를 특정 위치에 놓고 싶다면 새로운'View'를 넣을 위치 인 int를 취하는'addView' 메쏘드의 다른 풍미를 사용해야합니다 :'addView (text, 0); ' – Luksprog