그래서 저는 레이아웃을 알아 내고 레이아웃 인플레이터를 사용하려고했지만 몇 가지 문제가 있습니다. 나는이 개 상대적으로 XML 레이아웃 파일을 가지고, 하나의 XML 파일이 textViews, EDITTEXT 필드 및 스피너 객체가 있습니다내 견해가 모두 표시되지 않는 이유는 무엇입니까?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/goalNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dip"
android:text="@string/goalName" />
<EditText
android:id="@+id/goal_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/goalNameView"
android:hint="@string/editText"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/goalTasksView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/goal_tasks"
android:layout_alignBottom="@+id/goal_tasks"
android:layout_alignLeft="@+id/goalNameView"
android:text="@string/goalTasks" />
<Spinner
android:id="@+id/goal_tasks"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/goalTasksView"
android:layout_marginTop="51dp" />
</RelativeLayout>
다른 XML 파일은 하나의 텍스트 뷰 하나 개의 EditText 필드가 있습니다
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/tView"
>
<EditText
android:id="@+id/taskNameField"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/taskNameView"
android:ems="10"
android:hint="@string/editText" />
<TextView
android:id="@+id/taskNameView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/taskNameField"
android:layout_alignBottom="@+id/taskNameField"
android:layout_alignParentLeft="true"
android:text="@string/taskName"
/>
</RelativeLayout>
을
내가 세 번째 XML 파일 (main.xml에)와 함께 두 개의 레이아웃을 패치하기 위해 노력하고있어 :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/theMain"
>
<include android:id="@id/mainLayout" layout="@layout/activity_goal_keeper" />
</LinearLayout>
내가 레이아웃 작업을 찾고 있어요 방법은 ID @ (첫 번째 레이아웃을 표시하는 것입니다/firstLayout) 두 번째 레이아웃 (@ id/tView) 바로 아래에 있습니다. 나는 이것을 달성하기 위해 LinearLayout에 레이아웃을 구현해야한다는 것을 읽었습니다. 이것이 제가 세 번째 레이아웃 (@ id/theMain)을 갖는 이유입니다.
@ id/firstLayout에 대한 include 문이 있지만 @ main /를 통해 여러 버전의 @ id/tView를 확장하려고하기 때문에 @ id/tView에 대한 include 문이 없습니다. 액티비티 :
public class GoalKeeperActivity extends Activity implements AdapterView.OnItemSelectedListener {
public Integer[] items= {1,2,3,4,5,6,7,8};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
//setContentView(R.layout.activity_goal_keeper);
setContentView(R.layout.main);
Spinner numOfTasks=(Spinner) findViewById(R.id.goal_tasks);
numOfTasks.setOnItemSelectedListener(this);
ArrayAdapter<Integer> aa = new ArrayAdapter<Integer>(this, android.R.layout.simple_spinner_item, items);
aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
numOfTasks.setAdapter(aa);
ViewGroup item = (ViewGroup) findViewById(R.id.theMain);
for(int i=0; i<3;i++)
{
View child = getLayoutInflater().inflate(R.layout.tasks_view, item, false);
child.setId(i);
item.addView(child);
}
@firstLayout이 제대로 표시되지만 @tView가 전혀 표시되지 않습니다. 누군가 내가 누락 된 부분을 설명해 주시겠습니까?
미리 감사드립니다.
열린 'TextView' 태그와 관련이 있을지도 모르겠습니까? (위의 게시물에서 모두 검은 색으로 표시됩니다.) – Eric
@ Eric - 고마워, 우연히 삭제 했음에 틀림 없다. 문제의 오타 이기만하다. 원래 게시물을 수정하겠습니다. – Kyle