2012-02-23 11 views
0

[第二已修改]android - 最後添加的項目佈局是垂直的。爲什麼? (改造)

我發現其中的問題是。但我不知道它爲什麼這樣做。它不能成爲LinearLayout的邊緣(或者僅僅是marginLeft)。有人知道它爲什麼不能擁有?

[EDITED]

你好我有像bellow.And IAM從任何XML佈局以水平的LinearLayout添加TextViews佈局xml文件。這個佈局結構是給定的,我不能改變它。 最後添加的TextView始終垂直。我不知道爲什麼我在tottaly絕望。太多小時我嘗試*,但不知不覺。我只知道它不是在編程中添加TextViews .. 如果有些身體知道爲什麼它會這樣做,我會感激。

<RelativeLayout 

android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="@drawable/back_border" 
> 

<RelativeLayout 
android:id="@+id/manager_view_table_header" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:layout_alignParentTop="true" 
android:layout_alignParentLeft="true" 
> 


    <LinearLayout 
    android:id="@+id/layout_for_textViews" 
    android:orientation="horizontal" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"     
    android:layout_margin="6px" 
    android:layout_alignParentTop="true" 
    android:gravity="center_vertical" 
    android:background="@drawable/back_border" 
    > 
     <!-- horizontal layout, HERE IAM ADDING TEXTVIEWS --> 

    </LinearLayout> 

    </RelativeLayout> 

<!--What is here its no important 
    because, there is RelativeLayout with alignBellow relative layout before --> 

</RelativeLayout> 

和TextView的女巫IAM addig到的LinearLayout:

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content" 
     android:textSize="15sp" 
     android:paddingRight="7px" 
     android:paddingLeft="7px" 
     android:paddingTop="3px" 
     android:paddingBottom="3px" 
     android:layout_marginLeft="5px" 
     android:gravity="center_horizontal"  
     android:background="@drawable/background_table" 
     android:textColor="#330033" 
     android:text="Some text" 
     /> 
+0

爲什麼你有三個封閉的佈局? – Malcolm 2012-02-23 17:02:06

+0

你在談論什麼ListView?我沒有在您發佈的xml中看到一個。 – Turnsole 2012-02-23 17:03:32

+0

索裏..沒有的ListView但是TextView的。他們被封閉,因爲它只是我的主XML的一部分。其他的東西並不重要,我的意思是。 Sory爲我的糟糕的問題。我去改寫它..看到上面後在 – Juraj 2012-02-23 19:27:28

回答

0

我很困惑與你的三個佈局。 Wat是所有嵌套佈局的組成部分,嘗試使用單個相對佈局重新創建文本視圖,並使用android:layout_above和android:layout_below來放置文本視圖。

+0

,並圍繞這個三種佈局的其他意見,這並不重要,索裏對我的壞formuled的問題,我就重寫好。 – Juraj 2012-02-23 19:33:16

+0

我已經改變線性佈局,相對佈局,但沒有改變 – Juraj 2012-02-23 20:53:18

0

首先你需要重構這段代碼。

您可能想要使用實際的ListView來創建重複的元素。

,爲什麼在這個XML代碼三次宣佈,如果在頂部的根元素實際上只需要一旦xmlns:android="http://schemas.android.com/apk/res/android"

即使使用這樣的佈局來解決問題,如果其他的東西不工作一個不錯的想法是切換到圖形佈局(在Eclipse底部標籤上時,.xml文件),並嘗試手動設置第三TextView(而不是列表查看)手動調整高度,然後可以觀察更改並相應地完成它們。

+0

索裏我不能重構這個代碼..我編輯它更多的瞭解後:P .. SRY請檢查它。 – Juraj 2012-02-23 19:28:45

+0

我使用NetBeans,但我去找東西給它的圖形佈局 – Juraj 2012-02-23 20:34:00

3

嘗試使用android:padding =「6px」替換LinearLayout中的android:layout_margin =「6px」。 我認爲這將解決您的問題。我指的是新的LinearLayout應該是這樣的:

<LinearLayout 
android:id="@+id/layout_for_textViews" 
android:orientation="horizontal" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"     
android:padding="6px" 
android:layout_alignParentTop="true" 
android:gravity="center_vertical" 
android:background="#44ff435f" 
> 
+0

哇,,我想this..its working..Thanks .. – John 2012-02-24 04:20:10

+0

是的,它只是在做marginLeft,其未來unlogic比streched只是最後一個項目,馬比,因爲該textView有marginLeft,但仍然問題是爲什麼? – Juraj 2012-02-24 05:50:03