【问题标题】:Display TextView Bottom of the Screen in Android在Android中显示屏幕底部的TextView
【发布时间】:2011-08-10 06:40:25
【问题描述】:

在我的应用程序中, 我想在屏幕顶部显示一个具有屏幕宽度的 TextView。接下来要在该 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>

我想在此代码中进行哪些修改以获得我的结果??????

【问题讨论】:

  • 你为什么不使用RelativeLayout ?再次编辑布局,使其可以正常查看

标签: android layout textview


【解决方案1】:

试试这个

<?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>

【讨论】:

  • 只是好奇,你为什么需要android:layout_gravity="bottom"
【解决方案2】:

不要使用线性布局作为父布局,而是使用相对布局。 尝试使用以下代码

 <?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>

希望这会对你有所帮助...:)

【讨论】:

  • 但是作为开发人员我想知道是否可以通过线性布局来做到这一点?
  • @PrateekBhardwaj 是的,你也可以使用线性布局来做同样的事情。
【解决方案3】:

设置所有线性布局高度

android:layout_height="fill_parent"

【讨论】:

  • 如果我将 fill parent 设置为所有布局意味着 Top TextView 仅显示。
【解决方案4】:

为所有视图设置 android:layout_height="fill_parent" 属性,期望 TextView....

【讨论】:

  • 如果我这样设置意味着仅显示顶部 TextView。
  • 你用过RelativeLayout吗?我相信它会正常工作.. n 请正确编辑您的代码 bcz 某些代码不可见
  • 我使用了相对布局。现在我的顶部 textView 无法显示。 我将上面的东西用于顶部文本视图。
猜你喜欢
  • 2015-05-06
  • 2014-09-29
  • 2021-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多