그래,내가 이해하는 방법을 사용하여 포함 태그 그러나 나는've 은 문제로 실행합니다.
기본적으로 갖고 싶은 레이아웃 정의된 xml 에서는스트링고
이미지 뷰습니다. 나는 다음을 반복하에서 편안하고 필드를 채우에는 xml 레이아웃에 따라 무슨 배열(인구에 런타임). 따라서 여러 복사본을 만들의 xml 레이아웃과 채우는 필드의 독특한 데이터이다. 지금 나는've got 아이디어가 어떻게 다시 사용할 수 있습이
LinearLayout에서 이 방법으로는
스트링의 그리고`이미지 뷰의 이내에 그것을 일정한 id 와 필요 여러 복사본을 만들의 레이아웃이 있습니다.
방법은 없을 팽창시키 리소스 그리고 그것의 사본을 작동할 것입니다 그래서...
LinearLayout one = new LinearLayout(inflater.inflate(R.layout.home, container, false));
^없 생성자는 다음과 같습니다.
다른 방법은 어떻게하는 것입니다 그것은 모두 프로그래밍 방식으로 그러나 나의 원하는 특성의 보기와LinearLayout
xml 보다는 코드입니다. It's 같이 내가 원하는LinearLayout
템플릿이 될 수 있는 사본을 만들의 내 생각...정말로 확실하지 않는 경우에는's 가능합니다.
당신은 쉽게이 작업을 수행 할 수 있습니다,당신은 단지 그것을 깨다. 첫째로 당신은 레이아웃을 로드하는 삽입하려는 귀하의 동적으로 볼 수 있습니다. 다음을 팽창시키는 당신의 하위 보기고 채우 그것은 많은 시간으로 당신은 필요합니다. 다음에 추가하기 부모의 레이아웃,그리고 마지막으로 세트의 콘텐츠 뷰 활동을 부모에게 보기입니다.
여기's 예를 들어:
`` LayoutInflater inflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout 부모=(LinearLayout)inflater.팽창(R. 레이아웃이 있습니다.주,null);
for(int i=0;i<3;i++){ 뷰 지=inflater.팽창(R. 레이아웃이 있습니다.사용자 지정,null); 뷰 tv=(스트링)사용자.findViewById(R.id 입니다.텍스트); tv 가 있습니다.setText("사용자 지정 보"+i); 부모입니다.addView(사용자 정의); }
setContentView(부모); `` 기 main.xml 는 파일을 나에 삽입하기:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
그리고 여기에 custom.xml view 는 팽창을 채우고 동적으로 삽입하는:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
을 annyone 찾고 여전히 비슷한 솔루션을 분명히 사용할 수도 있습니다 include 직접 xml 에서는 여전히을 참조 할 수 있는 그들을 에서 코드:
LinearLayout row1 = (LinearLayout) findViewById(R.id.row1)
TextView text1 = row1.findViewById(R.id.text);
LinearLayout row2 = (LinearLayout) findViewById(R.id.row2)
TextView text2 = row2.findViewById(R.id.text);
출처:Romain 남자