如何使用滚动视图?

How to use a ScrollView?

这应该是一个滚动视图,其中包含从 API 收到响应时从 Java 代码添加的所有内容。

问题是我找不到在 ScrollView 中显示此类信息的方法。我尝试使用 ImageButton 但我无法获取其中的内容然后我尝试使用 Button 但仍然无法达到预期的效果请有人建议我可以这样做的方法。

private Button makeButton(String targetName, final String i, LinearLayout.LayoutParams buttonLayoutParams) {
    Button in = new Button(this);
    in.setBackground(getResources().getDrawable(R.drawable.rectangle14));
    in.setText(targetName);
    in.setWidth(360);
    in.setHeight(72);
    in.setLayoutParams(buttonLayoutParams);
    in.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent myIntent = new Intent(HomeActivity.this,XSavingDetailsActivity.class);
            myIntent.putExtra("i" ,i);
            HomeActivity.this.startActivity(myIntent);
        }
    });
    return in;
}

只需将 top-level 布局设为 ScrollView:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="1">

    <!-- everything else -->

</TableLayout>

你应该使用 RecyclerView .Each and every component within the RecyclerView is a CardView . Also you should learn about Material Design.

除了上面的一些有用的链接: https://developer.android.com/guide/topics/ui/layout/cardview.html https://www.androidhive.info/2016/01/android-working-with-recycler-view/ https://medium.com/@nileshsingh/android-cardview-101-everything-you-should-know-5bbf1c873f5a