2011-12-06 5 views
23

작은 안드로이드 응용 프로그램을 개발 중이고 레이아웃에 문제가 있습니다. XML에서 오류를 찾으려고했지만 찾을 수 없습니다 ...레이아웃 정의입니다. "layout_width 속성을 제공해야합니다."

오류 I 당신은 폭에서 지정할 필요가

<?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). 시도해보십시오.

<?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

: '여기

내 XML 파일입니다 ... "당신은 layout_width 속성을 제공해야"지고 있어요,하지만 난 그것을했고, 그것은 여전히 ​​작동하지 않습니다 및 뷰의 높이. 그것은 필수입니다. 텍스트 뷰의 경우 높이와 무게 만 설정합니다.

android:layout_width="0dip" 
3

없는 텍스트 뷰에 android:layout_width="wrap_content"을 추가 해보십시오.

+0

나는 이것을 항상 사용했지만 일반적으로 여러 항목에 대해 가중치를 사용하는 경우 0dp를 사용하려고합니다. 대부분 너비가 특정 비율이되기를 원하기 때문에 너비가 wrap_content 인 뷰를 갖는 것과 반대의 경우 무게를 사용하여 나머지 공간을 채우십시오. – kabuko

+0

0dip의 대안으로, 나는 가중치를 적용 할 때 종종 fill_parent/match_parent를 사용합니다. 그러나 그것은 OP의 재량에 달려 있습니다. – MrZander

+0

나는 그 역시 시도했지만, 나는 그것에 문제가 있었다. 일반적으로 작동하지만 가끔은 (이상한 것은 아니지만) 이상한 일이 발생하여 예상보다 커질 수 있습니다. 나는 물건을 화면에서 밀어내는 것에 문제가 있었다. – kabuko

3

제 경우에는 layout_width 속성을 TableLayout에 넣는 것을 잊었습니다.

그것의 TableLayout을의 아이가 그래서 나는이 문제에 달렸다 layout_width을 필요로하지 않습니다이다 TableRow beacuse 혼란 조금 ...

+0

나는 비슷한 문제가 있었다. XML에서 레이아웃을 확장하고 해당 XML의 루트로 TableRow를 사용하는 경우 TableRow의 너비를 지정해야합니다. – Tiago

1

난 u는 왜 코드 뭐야 폭 크기 후 dp을 넣어하지 않은 생각 작동하지 않을 수 있습니다. 예 android:layout_weight="20" 이것을 사용하십시오 android:layout_weight="20dp"

관련 문제