Android:是否可以在包含滚动浏览的布局中强迫任何屏幕溢出



我有一个简单的问题:是否有可能在包含 ScrollView的布局中强制屏幕溢出?

例如,如果我有以下布局:

<LinearLayout
    android:id="@+id/wrapper_table"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">     
    </LinearLayout>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </TableLayout>
    </ScrollView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">     
    </LinearLayout>
</LinearLayout>

如果TableLayout有很多TableRow,则Scrollview正在扩展到屏幕末端,并且较低的LinearLayout不太可见。是否可以强迫,没有设定的高度,ScrollView高度,以便让足够的空间显示较低的LinearLayout

谢谢!

android:layout_weight应用于ScrollView;这样,它将占用其他元素未占用的任何空间。

在下面的调整中,两个LinearLayout S将占用足够的空间来满足其内容,并且ScrollView将占用剩下的一切:

<LinearLayout
    android:id="@+id/wrapper_table"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">    
    </LinearLayout>
    <!-- This should be weighted height -->
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1">
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </TableLayout>
    </ScrollView>
    <!-- This should be wrap_content height -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">    
    </LinearLayout>
</LinearLayout>

是的,在您的外部线性布局中,设置" android:layout_weight"到每个元素,并使外层指定" stogesum"

喜欢:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/wrapper_table"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="1">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.1">     
    </LinearLayout>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.8">
        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </TableLayout>
    </ScrollView>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="0.1">     
    </LinearLayout>
</LinearLayout>

" strigesum"one_answers" layout_weight"指定了应使用多少屏幕的比率。在我的示例中,底部和顶部每个屏幕的10%,将80%作为中间滚动浏览(由tableview填写)

现在,我相信您还需要更改以使其高度为" Match_parent",因为您希望将所有80%的屏幕放置...仔细检查...

您必须更改的另一件事(取决于您的SDK&amp; editor)是每个内部元素的" layout_height"要为" 0dip",否则此机构可能无法正常工作,或者您会遇到错误

>

相关内容

最新更新