7

I am displaying a textview(I intend this to fill the entire screen excluding the button below it) and a button(small one at the bottom) in an activity. I want textview to be placed aove the button. I don't want to hardcode any height/width.

Hence For button I have kept height ad width as word_wrap For textview I have kept width as fill parent.

What I want to know is that, is there anyway by whcih I can specify textview height to be screenheight-button height. I want to this in xml file but not dnamically inside my code.

4

3 に答える 3

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>

ボタンの上にとどまり、画面全体に収まるテキストビューがあります。

于 2013-01-05T12:24:30.467 に答える
0

layout_weight属性を使用できます

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:text="TextView" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button" />

</LinearLayout>
于 2013-01-05T12:25:10.703 に答える
0

RelativeLayout を使用し、textview のサイズを fill_parent として設定し、その下にボタンを配置し、ボタンの android:layout_below="@+id/textview" とボタンのサイズを wrap_content として設定します。

ビジュアル デザイナーまたはデバイスで結果を確認してください。動作するはずです。

于 2013-01-05T12:23:14.737 に答える