以编程方式将自定义视图放入ScrollView(或Horizo​​ntalScrollView)(无滚动)

时间:2015-06-05 08:34:21

标签: android scrollview android-custom-view

我正在编程将自制视图(大小为3000px * 750像素)以编程方式放入任何scrollView。

我自定义视图的信息:它只是扩展了View,OnDraw()中只有一些绘图,没什么特别的。

为了收集绘图的所有信息,一旦AsyncTask加载了所有信息,就应该添加这个CustomView。

我的问题是,当我以编程方式将视图添加到包含ScrollView或Horizo​​ntalScrollview的任何ViewGroup时,没有滚动。

我尝试过多种布局,例如:

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView     xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:layout_marginTop="50dp" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:id="@+id/linLayoutScroll">

    </LinearLayout>
</HorizontalScrollView>

AsynTask完成后:

LinearLayout linLayout = (LinearLayout)rootView.findViewById(R.id.linLayoutScroll);
    linLayout.addView(new MyChartView(getActivity(), chartBuilder, ChartBuilder.DATASET.SPEED));*/

我尝试将我的视图添加到LinearLayout,但通常我的视图根本不会出现在屏幕上,或者没有滚动选项,我的视图会在显示结束时被切断。

我想必须有一些神奇的技巧告诉scrollView重新检查其内容并决定是否必须有滚动选项。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

错误发生在我的customView中。我没有设置视图的宽度和高度(setWidth(),setHeight())。因此,观点并不知道它到底有多大。 : - (

抱歉浪费你的时间!

相关问题