2

我有一个 Android 布局问题。我有一个显示器,我在其中将一些文本放入视图的中间,顶部有一个标题,底部有三个按钮。我遇到的问题是让 TextView(位于 ScrollView 内)拉伸以填满可用的屏幕空间。如果我将 ScrollView 的 layout_height 设置为“fill_parent”,则三个按钮将被推离屏幕底部。如果我将其设置为“wrap_content”,则它仅与支持放入 TextView 中的文本一样大。

这是我正在使用的布局的 XML:

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

<LinearLayout android:orientation="horizontal"
    android:gravity="top"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <ImageView android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher">
    </ImageView>
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        style="@android:style/TextAppearance.Large"
        android:text="@string/meetingdetail" />
</LinearLayout>

<ScrollView
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">
    <TextView android:id="@+id/meeting"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        style="@android:style/TextAppearance.Medium" />
</ScrollView>

<Button android:id="@+id/navigation"
    android:text="@string/naviation"
    android:onClick="meetingInfoOnClick"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

<Button android:id="@+id/mapsingle"
    android:text="@string/mapsingle"
    android:onClick="meetingInfoOnClick"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

<Button android:id="@+id/goback"
    android:text="@string/goback"
    android:onClick="meetingInfoOnClick"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />

</LinearLayout>

有人可以建议什么最能使带有 TextView 的 ScrollView 填满可用空间但仍然允许三个按钮出现?

4

2 回答 2

2

将 ScrollView 的高度设置为0dp并将其权重设置为1

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

<TextView android:id="@+id/meeting"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    style="@android:style/TextAppearance.Medium" />
</ScrollView>

但是,如果您不打算拥有多个可滚动视图,则应删除 ScrollView 并使用:

   android:scrollbars="vertical"

TextView 上的属性,因为 TextView 本身是可滚动的。

于 2013-01-04T21:18:25.687 回答
0

只需将您的 ScrollView 标记代码替换为..

<ScrollView
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView android:id="@+id/meeting"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    style="@android:style/TextAppearance.Medium" />
</ScrollView>

它会正常工作,如果您仍有任何问题,请告诉我。如果有效,则接受作为答案。

于 2013-01-04T21:19:57.373 回答