在按钮上方显示textview而不用xml中的高度编码

use*_*357 7 android

我正在显示一个textview(我打算将其填满整个屏幕,不包括它下面的按钮)和一个活动中的按钮(底部的小按钮).我想将textview放在按钮上.我不想硬编码任何高度/宽度.

因此,对于按钮,我将高度广告宽度保持为word_wrap对于textview,我将宽度保持为填充父级.

我想知道的是,无论如何,我可以指定textview高度为screenheight-button高度.我想在xml文件中使用它,但在我的代码中不是dnamically.

har*_*ore 5

要实现这一点,你必须创建这样的东西:

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/button1"
        android:text="TextView" />

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Button" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

你有一个文本视图,它将保持在你的按钮上方,适合整个屏幕.