Scrollview隐藏其他视图内容

时间:2017-08-13 09:24:08

标签: android android-linearlayout android-scrollview

我是android的新手。以下是我的活动xml。

我的问题是" linearLayoutTableViews"线性布局,如果我添加10个以上的按钮,它会隐藏"选择表"文本视图。如果我添加较少的视图(基本上没有填充完整的视图端口),我可以看到textview"选择表"。这是什么原因?我怎么解决它?

<LinearLayout
    android:layout_width="368dp"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="8dp"
    >

    <TextView
        android:id="@+id/textViewSelectTable"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="Select Table"
        android:textAlignment="center"
        android:textSize="30sp"
        android:textStyle="bold"
        android:visibility="visible"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="70dp" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="true"
        android:fillViewport="false"
        tools:layout_editor_absoluteX="8dp"
        tools:layout_editor_absoluteY="8dp">

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

        </LinearLayout>
    </ScrollView>
</LinearLayout>

3 个答案:

答案 0 :(得分:0)

TextView删除此邮件并生成android:layout_height="wrap_content",这将有效:

android:layout_height="0dp"
android:layout_weight="1"

答案 1 :(得分:0)

我看到你为一个线性布局子视图指定了权重属性。

android:layout_height="0dp"
android:layout_weight="1"

虽然没有为其他子视图指定权重(scrollview)

您是否可以尝试为scrollview指定相同的内容!

其次 - 如上所述 - 您可以使用相对布局作为scrollview的layout_below属性的替代方案。还没试过!

答案 2 :(得分:0)

线性布局在计算具有固定大小的视图后计算视图的权重。 这里有一个布局:

<LinearLayout
    android:layout_height="wrap_content"
    android:orientation="vertical"
    .
    .
    .
    >

<TextView
    .
    .
    .
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    .
    .
    .
    />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    .
    .
    .
    >
</ScrollView>

</LinearLayout>

因此它从scrollView中减去计算出的高度,然后计算权重。

我的建议。给scrollView一个权重或一个固定的高度。它是一个ScrollView,所以如果有任何额外的项目,它将滚动。

相关问题