【问题标题】:ScrollView height 0 even when fill_parentScrollView 高度 0 即使当 fill_parent
【发布时间】:2010-11-20 19:50:56
【问题描述】:

我有一个包含图像视图和滚动视图的线性布局 A。滚动视图包含第二个线性布局 B 这个想法是有一个固定的标题,而 linearLayout B 包含多个与滚动视图的高度完全匹配的视图。将其视为一个选项卡视图,其中所有选项卡在滚动视图中一个接一个。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/main_view"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000"
    android:orientation="vertical">

<ImageView android:id="@+id/logoImg"
    android:layout_width="fill_parent"
    android:gravity="center"
    android:src="@drawable/logo"
    android:layout_height="wrap_content"/>

<ScrollView
  android:id="@+id/scrollView"
  android:layout_weight="1"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"> 

<LinearLayout android:id="@+id/scrollLinear"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
</ScrollView>
</LinearLayout>

我试图通过在 scrollView 上调用 getHeight 来实现这一点,然后将此高度设置为 linearLayout B 中的每个视图,但 getHeight 始终返回 0。 任何人都知道实现这一目标的最简单方法是什么?

【问题讨论】:

  • 对不起,我不明白...你想要一个垂直的 tabview 的等价物吗?那为什么要使用滚动视图呢?
  • 好吧,我想要一个动画标签视图。如果您单击一个选项卡,则通过将滚动视图滚动到正确的位置来显示正确的选项卡。我觉得这看起来不错。我知道我可以使用 tabview 来实现相同的功能效果但不一样的视觉效果。

标签: android scrollview android-linearlayout


【解决方案1】:

嗯,这个问题很老了,但我会试试看 :) 会不会是ScrollView中缺少“fillViewport”?

  <ScrollView
    android:id="@+id/scrollView"
    android:layout_weight="1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    android:fillViewport="true" 

    >

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 2013-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多