【发布时间】:2013-03-29 09:56:34
【问题描述】:
首先,我在网上漫游寻找答案,但无法解决我的问题。
我在布局中有以下滚动视图:
<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<ImageView
android:id="@+id/img_cover_picture"
android:layout_width="128dp"
android:layout_height="128dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="12dp"/>
<LinearLayout
android:id="@+id/list_flags"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignBottom="@id/img_cover_picture"
android:layout_marginBottom="-12dp"
android:orientation="horizontal"
/>
<TextView
android:id="@+id/txt_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/img_cover_picture"
android:gravity="center_horizontal"
android:textColor="#F5F5F5"
android:textSize="28sp" />
<TextView
android:id="@+id/list_infos"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/txt_title"
android:textColor="#BABBBB"
/>
<LinearLayout
android:id="@+id/view_blog_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/list_infos"
android:layout_marginTop="8dp"
android:orientation="horizontal"
/>
<TextView
android:id="@+id/txt_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/view_blog_count"
android:gravity="center_horizontal"
android:textColor="#F5F5F5"
android:textSize="18sp" />
<LinearLayout
android:id="@+id/list_categories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txt_description"
android:layout_centerHorizontal="true"
android:layout_marginTop="8dp"
android:orientation="horizontal"
/>
</RelativeLayout>
</ScrollView>
以编程方式填充空的 LinearLayout。
我期望的是,当RelativeLayout中显示的内容太大时,ScrollView允许用户滚动查看所有内容。
问题是:当它发生时,他可以滚动,但最后一个 LinearLayout(由 list_categories 标识)从不显示。 我已经尝试了各种各样的事情:
- 也许因为它以编程方式填充它是空的?我尝试将其放在@id/view_blog_count 下方进行检查,并显示(覆盖描述)
- 我尝试将 fillViewport 设置为 true
- 我尝试更改权重
- 我尝试使用布局(_width|_height)
- ...
目前没有成功:(
感谢您的帮助!
加斯顿
更新
我知道 LinearLayouts 是空的,但它们是以编程方式填充的(我确信它们是)。此外,我尝试在空的 LinearLayout 中添加一个 TextView 作为测试,但 LinearLayout 仍然隐藏。
更新 2
我正在使用RelativeLayout,以便标志(list_flags)位于封面图片(img_cover_picture)之上。然而,正如@lelloman 所建议的那样,我确实尝试使用水平线性布局。它仍然没有工作:)
【问题讨论】:
-
如果您在 XML 中放置带有文本的 TextView 是否会显示?
-
是的,我做到了,但它仍然是隐藏的 :(
-
你真的需要一个相对布局吗?为什么不尝试使用线性布局呢?
-
感谢@lelloman 的建议,我最初使用 LinearLayout 以便“list_flags”视图位于“img_cover_picture”视图之上。不过我会试一试。编辑:好吧,它没有用,但还是谢谢你:)
-
我认为如果你确定那些线性布局不是空的,也许它们被其他视图重叠了......我个人讨厌 relativelayout ^^
标签: android android-linearlayout android-relativelayout android-scrollview