2011-04-21 192 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>