2014-01-19 118 views
1

一些XML佈局編碼所以我有問題......我應該複製此圖像XML Android的佈局問題

http://s28.postimg.org/n257m4dil/Untitled.png

但到目前爲止,我似乎只能遠遠得到這個和結帳按鈕拒絕留下來的權利,即使當我做採用Android:重力=「正確的」浮動的容器內吧...:/

http://s29.postimg.org/bqzspid13/pic3.png

這是我到目前爲止的代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".CartActivity" > 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textColor="#FFFFFF" 
     android:text="Shopping Cart" 
     android:background="@android:color/holo_blue_dark" /> 

    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:background="@android:color/holo_blue_light" 
     > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Subtotal:" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="#800000" 
      android:text="£???" /> 

     <Button 
      android:id="@+id/checkout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="right" 
      android:text="Checkout" > 
     </Button> 
    </LinearLayout> 
</LinearLayout> 

+0

你解決了這個問題? – Android

+0

非常感謝,問題解決了:) 但是我並不需要android:weightSum =「3」,使用它實際上使它遍佈各處。然而,將android:layout_weight =「1」放入兩個文本視圖解決了該問題,因此結帳按鈕不需要重新對齊:) – user3207096

回答

0

使用android:weightSum="3"爲你的內在

佈局的三個要素,並在此之後,

android:layout_weight="1"每個視圖

這將使意見舉行1/3的可用空間

<LinearLayout 
    android:id="@+id/linearLayout2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:background="@android:color/holo_blue_light" 
    android:weightSum="3" 
    > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Subtotal:" 
     android:layout_weight="1"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="#800000" 
     android:text="£???" 
     android:layout_weight="1" /> 

    <Button 
     android:id="@+id/checkout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="right" 
     android:text="Checkout" 
     android:layout_weight="1"> 
    </Button> 
</LinearLayout> 

編輯FILL_PARENT不贊成使用match_parent

+0

如果您的android:layout_width =「0dp」,最好的方法是。此外,你可以使android:weightSume =「100」(3也會很好),並讓孩子不平等。 20(0,5),20(0,5),60(2)。 – mamakurka

0

嘗試使用RelativeLayout的

<RelativeLayout 
    android:id="@+id/linearLayout2" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:text="Subtotal:" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_toRightOf="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="#800000" 
     android:text="£???" /> 

    <Button 
     android:id="@+id/checkout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:text="Checkout" > 
    </Button> 
</RelativeLayout>