【发布时间】:2013-11-26 12:02:25
【问题描述】:
我无法在 ScrollView 下看到最顶部的视图。 我已将滚动视图放在相对布局下。 ScrollView 有一个子布局,即具有一些按钮系列的线性布局。 问题是我无法看到 ScrollView 中出现的最顶部的视图。
下面是布局xml代码。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#217d27"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:onClick="backPressed"
android:text="Back"
android:textColor="#000" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
android:text="Heading Text"
android:textColor="#fff"
android:textSize="20sp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:onClick="homeButtonClicked"
android:text="Home"
android:textColor="#000" />
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fadingEdge="none"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#fff"
android:orientation="vertical" >
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Button 1"
android:textColor="@color/black" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Button 2"
android:textColor="@color/black" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Button 3"
android:textColor="@color/black" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Button 4"
android:textColor="@color/black" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Button 5"
android:textColor="@color/black" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Button 6"
android:textColor="@color/black" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Button 7"
android:textColor="@color/black" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Button 8"
android:textColor="@color/black" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Button 9"
android:textColor="@color/black" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Button 10"
android:textColor="@color/black" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Button 11"
android:textColor="@color/black" />
<Button
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:text="Button 12"
android:textColor="@color/black" />
</LinearLayout>
</ScrollView>
</LinearLayout>
请参阅屏幕截图以供参考。
【问题讨论】:
-
使用相对布局而不是线性布局。
-
Nope 相对布局也不起作用。我得到了同样的结果。
-
你的代码是 99% 完美的,只需删除 1 行只看我的答案我更新你的代码老兄,你总是欢迎 :)
-
谢谢老兄。它现在可以工作了。
-
我不应该在线性布局中使用这个 android:layout_gravity="center"。
标签: android android-layout android-scrollview