2009-07-08 68 views
2

我想在左邊放兩個TextView,在線性佈局裏面右邊一個按鈕,這可能嗎? 以下是我的代碼,我不得不硬編碼左邊的按鈕,這是不靈活的。是否可以佈置流向不同方向的兒童?android LinearLayout

<LinearLayout 
android:id="@+id/widget43" 
android:layout_width="fill_parent" 
android:layout_height="100px" 
> 
<TextView 
android:id="@+id/tc_buttom_text1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="Time elapsed" 
> 
</TextView> 
<TextView 
android:id="@+id/tc_buttom_text2" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="00:00:00 00" 
> 
</TextView> 
<Button 
android:id="@+id/tc2_home" 
android:layout_width="70px" 
android:layout_height="wrap_content" 
android:layout_marginLeft="200px" 
android:layout_marginRight="10px" 
android:text="Home" 
android:layout_weight="0.5" 
> 
</Button> 
</LinearLayout> 

回答

2

我想打好2周的TextView向左 ,和一個按鈕向右 線性佈局裏面,這是 可能嗎?

不與單個LinearLayout。您可能需要兩個LinearLayout(一個用於左邊兩個TextView s的列)或一個RelativeLayout。

是否可以佈置兒童 流向不同的方向?

如果通過「不同方向」同時指垂直和水平方向,則一個LinearLayout只能朝一個方向行進。使用嵌套的LinearLayoutRelativeLayout

0

LinearLayout有一個orientation屬性。嘗試這樣的:

<LinearLayout 
    android:id="@+id/widget43" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="100px" 
> 
1

您需要使用表佈局。查看API演示中的表格佈局示例。

Table layout - with 'stretch columns' = 1, 
-- Table row - with width = fill_parent, 
    -- Text View, 
    -- Text View, 
    -- Button, 

這將讓你的右鍵被推到了屏幕

1

要麼右邊緣使用兩個線性佈局(一個與水平方向和其他與垂直方向),或使用相對佈局。相對佈局是不是線性的,易強用

0

使用後:

<LinearLayout 
      android:id="@+id/widget43" 
      android:layout_width="fill_parent" 
      android:layout_height="100px" 
      android:layout_margin="16dp" 
      android:orientation="horizontal"> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 

       <TextView 
        android:id="@+id/tc_buttom_text1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Time elapsed"></TextView> 

       <TextView 
        android:id="@+id/tc_buttom_text2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:text="00:00:00 00"></TextView> 
      </LinearLayout> 

      <Button 
       android:id="@+id/tc2_home" 
       android:layout_width="70px" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="200px" 
       android:layout_marginRight="10px" 
       android:layout_weight="0.5" 
       android:text="Home"></Button> 
     </LinearLayout> 

對於更多的Android佈局教程和示例:http://www.viralandroid.com/2015/11/android-layouts.html