2013-10-30 28 views
1

我怎樣才能讓這個佈局:如何使用layout_weight在按鈕上方製作兩列布局?

layout

這是迄今爲止我的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="fill_parent" 
       android:orientation="vertical"> 

    <TextView 
     android:id="@+id/exampleText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Push the button" 
     android:background="#ffff00" 
     android:textColor="#000000" 
     android:textStyle="bold" 
     android:paddingLeft="5dip" 
     android:paddingRight="5dip" 
     android:layout_weight="1"/> 

    <Button 
     android:id="@+id/exampleButton" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="The button" 
     android:layout_weight="1"/> 
</LinearLayout> 
+0

幫我請怎麼樣chnage佈局像圖像? –

回答

1

你讓我用你的繪圖感謝笑:)順便說一句,你可以做到這一點與的TextView和一個按鈕如下圖所示:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:drawableLeft="@drawable/ic_launcher" 
     android:text="dummy text 1 \n dummy text 2" 
     android:gravity="center"/> 

    <Button 
     android:id="@+id/dummyButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="dummy" /> 

</LinearLayout> 

或者更復雜的東西:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/dummyImageView" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:background="#58FA58"/> 

     <LinearLayout 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:orientation="vertical" > 

      <TextView 
       android:id="@+id/myDummyTextView1" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:background="#DF013A" /> 

      <TextView 
       android:id="@+id/myDummyTextView2" 
       android:layout_width="match_parent" 
       android:layout_height="0dp" 
       android:layout_weight="1" 
       android:background="#2EFEF7" /> 
     </LinearLayout> 
    </LinearLayout> 

    <Button 
     android:id="@+id/dummyButton" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="dummy"/> 

</LinearLayout> 

或者與relativeLayout更高效。這將是另一個問題,read more about it。但是如果它足夠適合你,我更喜歡第一個。

+0

不,我想要像我的圖像imageview右兩個textview和底部的按鈕 –

+0

請查看我更新的答案。那對你會好的。但我建議你在理解Android上的佈局之後使用相對佈局。 – Devrim

+0

是很好,但有1個問題告訴我關於 –

相關問題