2013-03-05 58 views
0

末端添加複選框中的Android我有這樣的線性佈局: 在行中的LinearLayout

<!-- First column in row with image --> 
    <ImageView 
     android:id="@+id/bild" 
     android:layout_width="48dp" 
     android:layout_height="48dp" 
     android:layout_gravity="center" 
     android:layout_margin="8dp" 
     android:contentDescription="@string/description" 
     android:src="@drawable/ic_launcher" > 
    </ImageView> 

    <!-- Second column in row with data --> 

    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:paddingTop="10dp" > 

     <TextView 
      android:id="@+id/selectedItem" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textColor="#464f58" 
      android:textSize="16sp" 
      android:textStyle="bold" /> 

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

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="@string/numberOfLeaflet" 
       android:textSize="12sp" /> 

      <TextView 
       android:id="@+id/number" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="" 
       android:textSize="12sp" /> 
     </LinearLayout> 
    </LinearLayout> 

    <!-- Third column with checkBox --> 
    <CheckBox 
     android:id="@+id/chkBox" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

的問題是,該複選框是不可見的。 當我更改並在ImageView之前給這個複選框,然後我可以看到這個複選框。

你有什麼想法,爲什麼我不能在3列中看到這個複選框?

回答

0

第二列設置爲fill_parent寬度。所以最後一個複選框不適合,放在同一行,但離開屏幕一側。解決這個問題的最簡單的方法是使第二列不是fill_parent,或者使它和checkbox都是fill_parent,並使用權重使它們分割空間。您可以做的另一件事是將外部佈局設置爲RelativeLayout,以便您可以將第二列設置爲layout_left複選框並使複選框alignParentRight = true。

+0

謝謝。有用! – hipek 2013-03-05 21:34:02