2011-10-06 5 views
-1

아래 코드를 부풀려 싶습니다. (android API 데모의 list_item_icon_text.xml에서 가져옴).Android : xml 파일의 특정 섹션에 부풀기

<?xml version="1.0" encoding="utf-8"?> 
<!-- Copyright (C) 2007 The Android Open Source Project 

    Licensed under the Apache License, Version 2.0 (the "License"); 
    you may not use this file except in compliance with the License. 
    You may obtain a copy of the License at 

      http://www.apache.org/licenses/LICENSE-2.0 

    Unless required by applicable law or agreed to in writing, software 
    distributed under the License is distributed on an "AS IS" BASIS, 
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
    See the License for the specific language governing permissions and 
    limitations under the License. 
--> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ImageView android:id="@+id/icon" 
     android:layout_width="48dip" 
     android:layout_height="48dip" /> 

    <TextView android:id="@+id/text" 
     android:layout_gravity="center_vertical" 
     android:layout_width="0dip" 
     android:layout_weight="1.0" 
     android:layout_height="wrap_content" /> 

</LinearLayout> 

불행하게도, 데모, 인플레이션은 list14.java에

convertView = mInflater.inflate(R.layout.list_item_icon_text, null); 

를 사용하여 수행되었다.

위의 코드를 내 xml 파일에 포함하고 싶습니다.이 LinearLayout 만 부 풀리지 만 온라인으로 검색하고 몇 시간 동안 해보려고합니다. 나는이 시점에서 정말로 좌절하고있다. 나는 내가 원했던 것이 아닌 전체 XML 파일을 부 풀릴 수 있었다. 나는이 특정 섹션을 팽창시키고 싶다. (XML 파일에 추가했다.) 어떤 도움이라도 대단히 감사합니다.

답변

1
당신은 단지 '라고 my_layout.xml`하자 당신이 당신의 ID를 사용합니다 팽창 할 때, 당신의 layout 폴더에 파일을 저장해야합니다

:

 inflate(R.layout.my_layout); 

오른쪽 수입이 이루어되었는지 확인 . 내 R.java 파일을 가져 오는 것을 의미합니다.

 import my.packaage.com.R; 
+0

전체 레이아웃을 부 풀리지 않으려 고합니다. 위의 코드 만 내 파일에 추가했습니다. – OckhamsRazor

+0

더 좋은 질문은 : 그 android : id를 사용하여 LinearLayout을 부 풀릴 수 있습니까? – OckhamsRazor