滚动视图中的FrameLayout

时间:2020-01-15 12:32:38

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

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

<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);

    }
}

1 个答案:

答案 0 :(得分:0)

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