2011-12-06 5 views
23

は、私は少しのAndroidアプリを開発している、と私はレイアウトの問題を抱えている、私は私のXMLでエラーを発見しようとしてきたが、私はそれを見つけることができませんでした「なっM 『あなたはlayout_width属性を供給しなければならない』ですが、私はそれをやったし、それはまだ動作しません...ここでレイアウト定義。 msgstr "layout_width属性を指定する必要があります。"</p> <p>エラーI ...

は私の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="wrap_content" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="100" > 

    <TextView android:id="@+id/nombreEvento" 
     android:layout_height="fill_parent" 
     android:layout_weight="70" 
    /> 

    <TextView android:id="@+id/moneda" 
     android:layout_height="fill_parent" 
     android:layout_weight="10" 
    /> 

    <TextView android:id="@+id/totalEvento" 
     android:layout_height="wrap_content" 
     android:layout_weight="20" 
    /> 
    </LinearLayout> 

<TextView android:id="@+id/fecha" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
/> 

</LinearLayout> 

答えて

18

いや、あなたTextViewsのすべてがlayout_heightしており、代わりにlayout_heightのlayout_weightを追加layout_width(そしておそらくlayout_weight)。それを持っていないあなたのTextViewsにandroid:layout_width="wrap_content"を追加してみてください

<?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="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="100" > 

    <TextView android:id="@+id/nombreEvento" 
     android:layout_height="fill_parent" 
     android:layout_width="0dp" 
     android:layout_weight="70" 
    /> 

    <TextView android:id="@+id/moneda" 
     android:layout_height="fill_parent" 
     android:layout_width="0dp" 
     android:layout_weight="10" 
    /> 

    <TextView android:id="@+id/totalEvento" 
     android:layout_height="wrap_content" 
     android:layout_width="0dp" 
     android:layout_weight="20" 
    /> 
    </LinearLayout> 

<TextView android:id="@+id/fecha" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
/> 

</LinearLayout> 
+2

違いは何ですか? –

+1

@ AlikElzin-kilakaネストされたテキストビューはlayout_WEIGHT ... layout_WIDTHも持つ必要があります。 – ComeIn

2

あなたが幅をspecifiyする必要がありますおよびビューの高さ。それは必須です。テキストビューでは、身長と体重のみを設定しています。

android:layout_width="0dip" 
3

:これを試してみてください。

+0

私はいつもこれを使用していましたが、通常はいくつかの項目で重みを使用するときは0dpを使いたいと思っています。幅をwrap_contentにするのではなく、重量を使って残りのスペースを埋める。 – kabuko

+0

0dipの代わりに、私はweightを適用するときにfill_parent/match_parentを使うことがよくありますが、これは同じようです。しかし、それはOPの裁量に委ねられています。 – MrZander

+0

私もそれを試しましたが、私はそれに問題がありました。それは通常動作しますが、ときどき(しかし一貫してではありませんが)奇妙なことが起こります。私は物事がスクリーンから押し出されることに問題があった。 – kabuko

3

私の場合、layout_width属性をTableLayoutに入れるのを忘れていました。

それは私がこの問題に走ったのでlayout_widthを必要としないTableLayoutの子であるのTableRow beacuse少し混乱だ...

+0

私も同様の問題がありました。 XMLからレイアウトを膨張させ、そのXMLのルートとしてTableRowを持っている場合は、TableRowの幅を指定する必要があります。 – Tiago

1

私はuが、なぜあなたのコード.what幅サイズ後dpを入れていないと思います動作していない可能性があります。 ex android:layout_weight="20" これを使用android:layout_weight="20dp"

関連する問題