【问题标题】:Adding buttons and androidplot to a scrollview将按钮和 androidplot 添加到滚动视图
【发布时间】:2016-12-12 18:17:28
【问题描述】:

我似乎无法将按钮和 androidplot 一起放入滚动视图中,这样我就可以向下滚动,越过 androidplot 来查看按钮。我正在使用 androidplot 0.9.8。

这是我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ap="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="example.example.MainActivity">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/plotLayout">
            <com.androidplot.xy.XYPlot
                    android:id="@+id/plot"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    ap:Label="test"
                    ap:domainLabel="test"
                    ap:rangeLabel="test"
                    ap:renderMode="use_main_thread"/>
            <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:layout_below="@id/plot">
                    <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:text="test"/>
                    <Button
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:text="test"/>
                    </LinearLayout>
        </RelativeLayout>
</ScrollView>

编辑:但是,当我为 androidplot 指定某个高度(例如 android:layout_height="600dp" 而不是 android:layout_height="match_parent")时,它似乎可以正常滚动。为什么使用 match_parent 会阻止它滚动?

【问题讨论】:

  • 你的RelativeView没有正确关闭
  • 抱歉,错字。仍然遇到同样的问题

标签: android button scrollview androidplot


【解决方案1】:

看起来您正在使用 match_parent 的值作为绘图的高度,当在 ScrollView 内部使用时,这会创建一个鸡和蛋的场景,因为两个视图都依赖于另一个视图来告诉它它的大小会的。

最好的办法是在布局 xml 中为绘图提供明确的高度。如果这不适合您,请添加:

android:fillViewport="true"

到您的滚动视图的 XML 也可以解决问题。 (通常有效,但我在各种情况下听到了相反的报告)This blog post 更详细地介绍了基本问题。

【讨论】:

  • 我已经添加了 android:fillViewport="true" 无效(如原始帖子所示)。我试图将绘图高度设置为 Android 屏幕的大小,这意味着我无法在 xml 中明确声明它。似乎以编程方式执行它可能是目前最好的选择。不过还是谢谢
【解决方案2】:

我设法通过以编程方式为绘图设置手动大小来破解它。您可以获取绘图的布局参数,然后手动更改高度。我觉得身高好像有点问题?

XYPlot plot = (XYPlot) findViewById(R.id.plot);
LayoutParams lp = plot.getLayoutParams();
lp.height = 1710; // You can set it to whatever height you require it to be, 1710 is just an example
plot.setLayoutParams(lp);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 2019-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多