【问题标题】:FrameLayout inside Scroll view滚动视图内的 FrameLayout
【发布时间】:2020-01-15 12:32:38
【问题描述】:

我有一个很大的问题。我有 60 张图像(3 列和 20 行)添加到 FrameLayout 中。但有一个问题。我想通过 ScrollView 滚动这些图像。所以我添加了滚动视图,并在其中添加了 FrameLayout。但是这个滚动视图不起作用(它不滚动)。每个图像 ig 都很好,但一个问题是它不 srcoll。请帮帮我。

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="0dp">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/frame1"/>
</ScrollView>
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x/3;
int height = size.y/3;
iparams =  new FrameLayout.LayoutParams(width,  width);

for (int y = 0; y < 20;  y++) {
    for (int i = 0; i < 3; i++) {

        final ImageView car = new ImageView(SecondActivity.this);
        car.setImageResource(R.drawable.car_0);
        car.setLayoutParams(iparams);
        car.setId(i+3*y);
        car.setY(y * width);
        car.setX(i * width);
        frameLayout.addView(car);

    }
}

【问题讨论】:

  • 为什么不使用带有网格布局管理器的recyclerview?
  • 你试过NestedScrollView吗?您还可以分享结果视图的屏幕截图吗?
  • 使用 GridLayoutManager 和 RecyclerVIew 可以轻松实现您想要的功能。请参考abhiandroid.com/materialdesign/recyclerview-gridview.html
  • 尝试在你的 for 之后添加 frameLayout.onLayout()
  • @Sam 平滑滚动,我有点困惑,因为我无法弄清楚输出

标签: java android scrollview android-scrollview android-framelayout


【解决方案1】:

在这种情况下,最好将 RecyclerView 与 GridLayoutManager 一起使用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-09
    • 2014-04-20
    • 1970-01-01
    相关资源
    最近更新 更多