当嵌入 Horizo​​ntalScrollView 中时,我的自定义视图不可见

发布于 2024-11-26 08:36:15 字数 1220 浏览 5 评论 0原文

我知道很多人都遇到过类似的问题,但我找不到解决方案。我创建了一个扩展 SurfaceView 的自定义视图。当我使用时,这个视图工作得很好:

setContentView(graphView);

但是我希望它嵌入到 Horizo​​ntalScrollView 中。如果我尝试使用 xml 执行此操作:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">

<com.stuff.graph.GraphView
android:id="@+id/graph"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

</HorizontalScrollView>
</FrameLayout>

然后我会收到致命异常,并且我的应用程序将关闭。

如果我尝试通过以下方式以编程方式解决此问题:

graphView = new GraphView(this);
graphView.setVisibility(View.VISIBLE);
myScrollView = new HorizontalScrollView(this);

graphView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
myScrollView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));        

myScrollView.addView(graphView);      

setContentView(myScrollView);

那么屏幕就变成黑色了。我还尝试了上面显示的代码的许多变体,但没有成功。我哪里错了?

I know a lot of people have had similar issues to this but I cannot find a solution. I have created a custom View which extends SurfaceView. This view works perfectly when I use :

setContentView(graphView);

However I want it to be embedded inside a HorizontalScrollView. If I try this with xml with:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">

<com.stuff.graph.GraphView
android:id="@+id/graph"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

</HorizontalScrollView>
</FrameLayout>

Then I get a fatal exception and my application closes.

If I try to solve this programatically with:

graphView = new GraphView(this);
graphView.setVisibility(View.VISIBLE);
myScrollView = new HorizontalScrollView(this);

graphView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
myScrollView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));        

myScrollView.addView(graphView);      

setContentView(myScrollView);

Then the screen is just black. I've also tried many variations on the code shown above but none have been successful. Where am I going wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

记忆里有你的影子 2024-12-03 08:36:15

您应该能够在 xml 中获取它,没有问题 - 尝试将自定义图形视图嵌入滚动视图内的 ListView 中;根据我使用horizo​​ntalScrollView的经验,他们往往对内容非常挑剔。如果这不起作用,请尝试测试框架视图是否存在问题。只需向水平滚动视图添加一个按钮,看看是否可以显示该按钮。如果没有,则尝试显示框架时出现问题,并且与您的自定义代码无关。

You should be able to get it in xml no problem - try embedding your custom graph view inside a ListView inside the scroll view; in my experience with horizontalScrollView they tend to be very pick about their contents. If that doesn't work, try testing to see if there is a problem with the frame view. Just add a button to the horizontal scroll view and see if you can get that to show up. If not, then there is a problem trying to display the frame, and it has nothing to do with your custom code.

泅人 2024-12-03 08:36:15

事实证明,这并不是解决此问题的真正方法:

http ://www.mail-archive.com/[email protected]/msg45804.html

我的解决方案是我不会使用SurfaceView,相反,我可能会绘制位图并将其放入图像视图中,然后将其放入 ScrollView 中。

Turns out this isn't really the way to solve this issue:

http://www.mail-archive.com/[email protected]/msg45804.html

My solution is that I'm not going to use SurfaceView, instead I'm probably going to draw to a Bitmap and put that in an imageview which I can then put inside a ScrollView.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文