2011-08-02 16 views
1

R.id.catTextと膨らんでいますが、それを膨張させても表示されません。私がを膨らませてR.id.assets(コンテナ)の場合、両方の要素がうまく表示されます。私はちょうどコンテナを望んでいない。どうすればいいですか膨らませるR.id.catTextを膨張させずにR.id.assetsを付けないでください。膨らんだビューと要素を膨らますと

また、を膨らませてR.id.catTextをオブジェクトに追加できますか?例えば。

TextView catText = inflater.inflate(R.id.catText); 
someView.addView(new catText()); 

私のコード:

LinearLayout myRoot = (LinearLayout) findViewById(R.id.assets); 
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View view = inflater.inflate(R.layout.assets, myRoot, false); 

私のスタイル:XMLレイアウトからViewオブジェクトを作成

<?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:weightSum="1" 
android:padding="50px" android:id="@+id/assets"> 
    <TextView android:id="@+id/catText" android:text="TextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#ff0000"></TextView> 
</LinearLayout> 

答えて

2

LayoutInflaterR.layout.*でのみ動作します。 TextViewだけを膨らませたい場合は、独自のレイアウトXMLファイルに配置する必要があります。コンテナが必要な場合は必要に応じて、コンテナのレイアウトにTextViewを含めることができます。 catText.xmlで

:コンテナXMLファイルに

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/catText" 
    android:text="TextView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#ff0000"/> 

<?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:weightSum="1" 
    android:padding="50px" 
    android:id="@+id/assets"> 
    <include layout="@layout/catText"/> 
</LinearLayout> 

次にあなたが必要な方1膨らませることができます。

+0

私はこの質問に答えると信じています。 – Jacksonkr

0

は本当にフレートコールを必要としません。ビューの初期化にはfindViewByIDを使用する必要があります(この場合はTextView)。

TextViewにインフレータブルコールを使用しようとしているところを正確に説明できますか?

+0

TextViewを複数回使用したいと思います。私はちょうどXMLでそれをスタイリングして、アプリでそれを使いたいと思っています。今はループです。 – Jacksonkr

関連する問題