Android 如何制作带有图像/按钮的大型滚动屏幕?

Android 如何制作带有图像/按钮的大型滚动屏幕?,android,xml,android-studio,android-layout,scroll,Android,Xml,Android Studio,Android Layout,Scroll,我有以下代码: 首先,您需要使用recyclerview 您的“活动”视图将包含以下代码 <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button and

我有以下代码:



首先,您需要使用recyclerview

您的“活动”视图将包含以下代码

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <Button
                android:id="@+id/buttonAction"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="button action" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="vertical"
                android:scrollingCache="true" />
        </LinearLayout>

就这些。

你会有一个数字图像吗?你能发布整个xml吗?是的,最初我会有0个图像,当按下按钮时,会出现新的图像。到目前为止,xml是一个非常大的文件,所以我不知道它是否会太有用,但如果它有帮助的话,我可以发布它。好的evan,你需要学习recyclerview给我一分钟,我会发布一个解决方案Kay真棒,非常感谢,我是android新手,非常感谢
   <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <ImageView
            android:id="@+id/image"
            android:layout_marginTop="4dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="centerCrop"
            android:adjustViewBounds="true"
            android:src="@drawable/image_1"/>
    </LinearLayout>
public class CardAdapter extends RecyclerView.Adapter<CardAdapter.ViewHolder> {

    Context context;

    public void setContext(Context context) {
        this.context = context;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imgCover;

        public ViewHolder(final View itemView, int type) {
            super(itemView);
            imgCover = itemView.findViewById(R.id.image);
        }
    }

    @Override
    public int getItemViewType(int position) {
        return 1;
    }

    @NonNull
    @Override
    public CardAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = null;
        RecyclerView.LayoutParams lp;

        switch (viewType) {
            case 1:
                view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_card_payment, null, false);
                lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                view.setLayoutParams(lp);
                break;
        }
        return new CardAdapter.ViewHolder(view, viewType);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    }

    @Override
    public int getItemCount() {
        return 10;
    }

    public Context getContext() {
        return context;
    }
}
public class CardsActivity extends AppCompatActivity {

    RecyclerView recyclerView;
    CardAdapter cardAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cards);

        initToolbar();
        recyclerView = findViewById(R.id.recyclerView);
        cardAdapter = new CardAdapter();
        cardAdapter.setContext(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));

        recyclerView.setHasFixedSize(true);
        recyclerView.setNestedScrollingEnabled(false);
        recyclerView.setAdapter(cardAdapter);
    }



}