【问题标题】:How to use a ScrollView?如何使用滚动视图?
【发布时间】:2018-04-03 07:02:46
【问题描述】:

这应该是一个滚动视图,当从 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;
}

【问题讨论】:

  • 使用RecyclerView
  • 您应该使用ListViewRecyclerView

标签: java android android-layout android-studio scrollview


【解决方案1】:
【解决方案2】:

只需将顶层布局设置为 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-09
    • 2012-03-10
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多