2011-04-21 190 views
8

在我的應用程序中, 我想在屏幕頂部以屏幕寬度顯示一個TextView。接下來想要在TextView下面顯示圖形視圖。接下來在圖形視圖下方顯示一個文本視圖。在Android中顯示TextView屏幕底部

我用下面的xml代碼。在我的代碼TextView不能顯示在屏幕底部。

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

<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
> 
<TextView 
android:orientation="horizontal" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="@string/hello" 
android:background="#FF8A11" 
android:padding="8dip" 
/> 
</LinearLayout> 



<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
> 
<com.game.viewdot.ViewDot 
android:id="@+id/DrawView" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
/> 
</LinearLayout> 



<LinearLayout 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:gravity="bottom" 
android:layout_gravity="bottom" 
> 

<TextView 

android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="Another Text View" 
android:background="#FF8A11" 
android:padding="8dip" 
android:gravity="bottom" 
android:layout_gravity="bottom" 
/> 

</LinearLayout> 

我希望把這個代碼讓我的結果是什麼修改??????

+1

你爲什麼不使用'RelativeLayout'?再次編輯佈局,以便它可以正常瀏覽 – 2011-04-21 12:23:55

回答

7

使用相對佈局。 嘗試使用下面的代碼

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 

     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/relative01" 
     > 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" 
     android:background="#FF8A11" 
     android:padding="8dip" 
     android:id="@+id/textView01" 
     /> 
     <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/textView01" 
    > 
    <com.game.viewdot.ViewDot 
android:id="@+id/DrawView" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
/> 
    </LinearLayout> 



    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_alignParentBottom="true" 
    > 

    <TextView 

    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Another Text View" 
    android:background="#FF8A11" 
    android:padding="8dip" 

    /> 

    </LinearLayout> 

    </RelativeLayout> 

希望這將幫助你... :)

+0

非常感謝。其工作正常。 – 2011-04-21 13:04:37

+0

但作爲一名開發人員,我想知道這是否可以通過線性佈局來實現? – 2017-12-26 09:57:13

+0

@PrateekBhardwaj是的,你也可以使用線性佈局來做同樣的事情。 – 2018-02-21 10:14:10

0

集中所有的LinearLayout高度

android:layout_height="fill_parent" 
+0

如果我將填充父項設置爲全部佈局意味着只顯示頂部TextView。 – 2011-04-21 12:22:43

0

集機器人:layout_height = 「FILL_PARENT」 屬性對所有查看預期,而不是使用的LinearLayout作爲父佈局的TextView ....

+0

你可以使用RelativeLayout來代替Linear .. – 2011-04-21 12:24:13

+0

如果我這樣設置意味着只顯示頂級TextView。 – 2011-04-21 12:29:49

+0

你用過RelativeLayout嗎?我相信它會工作得很好.. n plz正確編輯你的代碼bcz一些代碼是不可見的 – 2011-04-21 12:33:16

13

試試這個

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_gravity="bottom"> 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/ContentView" 
android:layout_gravity="bottom" android:layout_alignParentBottom="true"/> 

</RelativeLayout>