2011-07-05 9 views
1

행이 채워진 ListView가 있습니다.LinearLayout layout_weight

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:paddingLeft="8dip" 
android:weightSum="100"> 
<TextView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/columnA" 
    android:layout_weight="30" 
    android:layout_gravity="center"/> 
<TextView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/columnB" 
    android:layout_weight="30" 
    android:layout_gravity="center"/> 
<ImageView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:src="@drawable/icon" 
    android:id="@+id/columnC" 
    android:layout_weight="10" 
    android:layout_gravity="center" 
    > 
</ImageView>  
<CheckBox 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/columnD" 
    android:layout_weight="30" 
    android:layout_gravity="center"/> 

문제는 내 행이 동일하게 세에서 간격되도록 내가의 columnC 항목 및 COLUMNB 항목이 서로 매우 가까이 할 것입니다 :처럼이 행이 보이는 XML 파일에서 온 부품, 즉 : columnA, (columnB + columnC) 그리고 columnD. 내가 볼 수 있듯이 layout_weight를 사용하여이 작업을 수행하려고 시도했지만 위의 코드는 반대의 효과가있는 것 같습니다. columnA와 columnB는 왼쪽에서 매우 부각되며, C 열은 자체적으로 큰 공간에서 떠 다니는 것처럼 보입니다. 그런 다음 columnD는 columnC 근처에 위치하며 오른쪽에 너무 많은 공간이 있습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까? : s

답변

0

나는 당신이 columnC와 columnB가 같은 가중치를 가지길 원하지만, 그것들을 다르게 설정했다고 생각할 것이다.

COLUMNA보십시오 : 무게 =

2 COLUMNB가 : 무게 =

1 columnC : 무게 = 1

columnD : 무게 = 2

내가 가진 매우 제한된 경험을 체중 속성과 함께하지만 나는 이것이 당신이 원하는 결과를 얻을 수있는 방법이라고 생각합니다.

아직 문제가있는 경우 화면의 모습과 모양을 스크린 샷으로 게시 할 수 있도록 도와주세요.

+0

그것에 나를 이길 그들을 동등하게 만들려고 노력하지 않아도 내가 게시하기 전에. – Maximus

+0

두 분 모두 덕분에 분명히 좋아 보이지만 columnD는 여전히 오른쪽에 너무 많은 공간이있는 columnC에 너무 가까이에 나타납니다. ■ 체크 박스와 관련이 있습니다. –

+0

괜찮아요 -이 나머지 문제를 해결하기 위해 linearlayout에서 내 체크 박스를 감싸고 선형 레이아웃에서 무게와 중력을 설정해야합니다. 고마워! –

2

시도해보십시오. 기본적으로 각보기가 가중치/총 가중치로 "원하는"공간을 파악할 수 있습니다. 당신은 순간까지 "로드 1 새 응답"을 못해서 ... 얼마나 너무 의해 몰랐어요 (100)

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="8dip" 
    android:weightSum="100"> 
<TextView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/columnA" 
    android:layout_weight="2" 
    android:layout_gravity="center"/> 
<TextView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/columnB" 
    android:layout_weight="1" 
    android:layout_gravity="center"/> 
<ImageView 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:src="@drawable/icon" 
    android:id="@+id/columnC" 
    android:layout_weight="1" 
    android:layout_gravity="center" 
    > 
</ImageView>  
<CheckBox 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:id="@+id/columnD" 
    android:layout_weight="2" 
    android:layout_gravity="center"/>