【问题标题】:Fill whole screen scrollview android填充整个屏幕滚动视图android
【发布时间】:2015-12-07 20:26:05
【问题描述】:

我无法用滚动视图填满整个屏幕。

如何让滚动视图覆盖整个屏幕宽度和屏幕高度?我尝试使用 fillviewport 但这适用于屏幕高度。

我不确定是滚动视图还是它的父级 (FrameLayout) 有问题?

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

<ScrollView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:fillViewport="true">

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


 <ImageView
    android:id="@+id/img1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="img1"/>

 <TextView 
     android:id="@+id/text_img1"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:visibility="gone"
     />

 <ImageView
    android:id="@+id/img2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="img2"/>

 <TextView 
     android:id="@+id/text_img2"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:visibility="gone"
    />

<ImageView
    android:id="@+id/img3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="img3"/>

 <TextView 
     android:id="@+id/text_img3"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:visibility="gone"
    />

    </LinearLayout>
</ScrollView>

【问题讨论】:

  • @BartoszLipinski - 是的 - android.app.AlertDialog

标签: android android-layout android-scrollview


【解决方案1】:

像这样更改您的 ScrollViewLinearLayout

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

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

【讨论】:

  • 谢谢,但没有成功
【解决方案2】:

将您的 &lt;ScrollView&gt;wrap_content 更改为 match_parent

例子:

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center">

另外,you should be using match_parent instead of fill_parent in API 8+

编辑:

在cmets聊了一会儿,我和OP发现FrameLayout的默认背景是透明的,也就是说你可以看到下面的旧视图。

使用LinearLayout 或其他任何东西代替FrameLayout 将解决此问题。

【讨论】:

  • @java 很有趣。您使用 FrameLayout 有什么特别的原因吗?尝试将其更改为 LinearLayout,或尝试为 FrameLayout 设置背景颜色。
  • 是的——你是对的,我一直在想这个。我会尝试改变它(我笨拙 - 我现在可以看到 Android Lint 告诉我 FrameLayout 或 ScrollView 没用。
  • @java 太好了!我很高兴能帮你解决这个问题。我会更新我的答案,如果您能接受它是正确的答案,我将不胜感激,以便未来看到此问题的开发人员会看到我们找到了解决方法。 :)
  • 是的,如果它有效,我会这样做,但如果我使用 LinearLayout 作为父级,则会出现同样的警告
【解决方案3】:

其他答案正朝着正确的方向发展,但您的主要问题可能是因为它是Dialog

首先确保您的Dialog 是无边界的。您可以使用here 建议的方法之一(不要重复答案)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多