ViewFlipper高度问题

3
在下面的代码中,viewflipper 没有占满整个屏幕,它只是包裹着 textview。为什么会这样?
<?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="match_parent"
    android:orientation="vertical" >

    <ScrollView  
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#0000ff" >

        <ViewFlipper android:id="@+id/ViewFlipper01"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#aa0000"
            android:layout_gravity="center">  

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"></TextView>

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

1
在scrollView中尝试使用android:fillViewport="true" - Mohsin Naeem
1
@MMohsinNaeem 这就是答案,如果您将其写成答案,我会标记它,谢谢。 - John Watson
3个回答

5
在scrollView中使用 android:fillViewport="true"

在ConstraintLayout中,尝试使用android:layout_height="0dp"... - Pat Lee

0
<ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0000ff" >

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ViewFlipper android:id="@+id/ViewFlipper01"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#aa0000"
        android:layout_gravity="center">  

        <TextView
            android:layout_width="match_parent"
            android:layout_height="50dp">
        </TextView>

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

这将会起作用。


-1
为什么要增加ViewFlipper的高度?ViewFlipper的高度取决于您在其中添加的内容或视图。因此,ViewFlipper的高度和宽度将始终等于您为视图提供的最大高度/宽度。在您的情况下,这是一个文本视图,因此,如果您增加当前视图的高度或添加另一个高度大于当前视图的textView,ViewFlipper的高度将会增加。

因为ViewFlipper只占据了屏幕的一半,看起来不太好,所以我想让它的内容扩展并占用更多的空间,因此需要扩展ViewFlipper。 - John Watson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接