【发布时间】:2014-07-15 12:09:00
【问题描述】:
我的滚动视图中有一些线性布局和一些视图,覆盖了整个屏幕。问题是我可以看到我的一个小部件在屏幕下方,它不会向下滚动。这是我的xml文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<ScrollView
android:id="@+id/mainScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="vertical" >
<LinearLayout
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/topLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textDateTime"
android:layout_width="wrap_content"
android:text="@string/nullString"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFCCFF99"
android:textSize="25sp" />
<LinearLayout
android:id="@+id/buttonsLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="5dp"
android:orientation="horizontal" >
<Button
android:id="@+id/buttonReset"
style="?android:attr/buttonStyleSmall"
android:layout_width="130sp"
android:layout_height="40dp"
android:background="@drawable/button"
android:text="@string/buttonResetText"
android:textColor="#000000"
android:textSize="20sp" />
<Button
android:id="@+id/buttonFreeze"
style="?android:attr/buttonStyleSmall"
android:layout_width="130sp"
android:layout_height="40sp"
android:layout_marginLeft="5dp"
android:background="@drawable/button"
android:text="@string/buttonFreezeText"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
</RelativeLayout>
<ProgressBar
android:id="@+id/loadBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="118dp"
android:layout_height="118dp"
android:layout_gravity="center" />
<GridView
android:id="@+id/sensorsGrid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#FFCCFF99"
android:gravity="center"
android:numColumns="6"
android:stretchMode="none" >
</GridView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
我还在这样的代码中向 mainLayout 添加了一个 GraphView
graph = new LineGraphView(this, "GraphViewDemo");
graph.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 300));
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.mainLayout);
mainLayout.addView(graph);
另一个问题是,如果 GridView 不垂直适合主布局(因为它更大),则 gridView 变得可滚动(我不想要)并且下面的 GraphView 看不到并且我无法滚动归根结底
更新: 当前的xml
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="${relativePackage}.${activityClass}"
android:id="@+id/mainScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="vertical" >
<LinearLayout
android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF023458"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/topLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textDateTime"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_margin="5dp"
android:text="@string/nullString"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFCCFF99"
android:textSize="25sp" />
<LinearLayout
android:id="@+id/buttonsLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="5dp"
android:orientation="horizontal" >
<Button
android:id="@+id/buttonReset"
style="?android:attr/buttonStyleSmall"
android:layout_width="130sp"
android:layout_height="40dp"
android:background="@drawable/button"
android:text="@string/buttonResetText"
android:textColor="#000000"
android:textSize="20sp" />
<Button
android:id="@+id/buttonFreeze"
style="?android:attr/buttonStyleSmall"
android:layout_width="130sp"
android:layout_height="40sp"
android:layout_marginLeft="5dp"
android:background="@drawable/button"
android:text="@string/buttonFreezeText"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
</RelativeLayout>
<ProgressBar
android:id="@+id/loadBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="118dp"
android:layout_height="118dp"
android:layout_gravity="center" />
<GridView
android:id="@+id/sensorsGrid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="#FFCCFF99"
android:gravity="center"
android:numColumns="6"
android:stretchMode="none" >
</GridView>
</LinearLayout>
</ScrollView>
【问题讨论】:
-
你为什么不简单地删除父级 RelativeLayout 而让你的 ScrollView 成为父级?
-
哦,是的,好点,我现在删除了它,但结果还是一样:/
标签: android xml android-layout android-scrollview