通过覆盖 onConfigurationChanged 旋转手机时更改 Horizo​​ntalScrollView 中的内容大小

发布于 2024-09-02 02:24:14 字数 914 浏览 2 评论 0原文

Android 用户大家好...

我在旋转手机时调整 Horizo​​ntalScrollView 中的内容大小时遇到​​问题。我在包含 Horizo​​ntalScrollView 的活动中覆盖 onConfigurationChanged,因为我想自己处理大小调整。但是,我在寻找应该调整内容大小的位置时遇到了很大的问题。 Horizo​​ntalScrollView 本身具有 FILL_PARENT 作为宽度和固定高度。这个想法是,它应该始终沿宽度方向填充屏幕,同时具有多个内容单元格,每个单元格与 Horizo​​ntalScrollView 本身一样宽。

我的 Horizo​​ntalScrollView 中的内容由一个 LinearLayout(我们称之为wrapperLayout)和其中的多个 LinearLayout 组成。当手机旋转时,我只想更改wrapperLayout内所有LinearLayout的宽度。当我通过将其放入 onInterceptTouchEvent(MotionEvent ev) 中来测试调整大小代码时,这很容易做到并且效果很好,也就是说,视图的大小就像我触摸 Horizo​​ntalScrollView 时应该调整的那样。

当我试图找到一个执行调整大小代码的好位置,以便在旋转手机时自动调整大小时,困难就出现了。我已经尝试了 requestLayout、onSizeChanged、onLayout、onConfigurationChanged 和其他一些可能的组合,并在调整大小代码之前和之后改变了对 super (如果有)的调用。我无法完成这项工作(即使执行了调整大小代码,视图也没有调整大小),这确实令人沮丧。我已经做了很多日志记录,以确保 Horizo​​nalScrollView 在调用我的调整大小代码之前确实更改了宽度,但无济于事。

有人知道发生了什么事吗?当我像这样自己处理onConfigurationChanged时,会调用哪些方法以及按什么顺序调用?

提前致谢

Hello fellow Androiders...

I have a problem with resizing content in a HorizontalScrollView when the phone is rotated. I'm overriding onConfigurationChanged in my activity containing the HorizontalScrollView, since I want to handle the resizing myself. However, I'm having great problem finding where i should put the resizing of the content. The HorizontalScrollView it self has FILL_PARENT as width and a fixed height. The idea is that it should always fill the screen width-wise, while having several cells of content, each as wide as the HorizontalScrollView itself.

The content in my HorizontalScrollView consists of one LinearLayout (let's call it wrapperLayout) with several LinearLayouts inside it. When the phone rotates I simply want to change the width of all the LinearLayouts inside the wrapperLayout. This is easy to do and works great when I test the resizing code by putting it in onInterceptTouchEvent(MotionEvent ev), that is the views are resized just as they are supposed to when I touch the HorizontalScrollView.

The difficulty appears when I try to find a good spot to execute resizing code, so that the resizing happens automatically when the phone is rotated. I have tried all possible combinations of requestLayout, onSizeChanged, onLayout, onConfigurationChanged and a few others and varying their calls to super (if any) before and after the resizing code. I can not make this work (the views are not resized even though the resize code is executed) and it is really frustrating. I've done a lot of logging to make sure the HorizonalScrollView really has changed width before calling my resize code but to no avail.

Does anyone have any clue as to what is going on? What methods are called and in what order when I handle the onConfigurationChanged by myself like this?

Thanks in advance

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

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

发布评论

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

评论(1

宫墨修音 2024-09-09 02:24:14

您不使用视图控制器的方向调用是否有原因?即

// Override to allow orientations other than the default portrait orientation.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

我认为这可能更容易。

Is there a reason you are not using the viewcontroller's orientation calls. i.e.

// Override to allow orientations other than the default portrait orientation.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

I think it might be easier.

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