android studio 相册类应用的编写

如图-图片说明
图片说明
由于是在国外上学所以上课老师讲的操作可以跟上但是还是有些地方没有听明白,作业要让用activity_main.xml, dialog.xml, strings.xml MainActivity.java来表示,我只写了activity_main.xml,MainActivity.java,而且还读不出来,想让大手看看哪里出了错,如果大神能帮忙解释一下dialog.xml, strings.xml 这两个怎么写,小弟万分感谢
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <GridView
        android:numColumns="auto_fit"
        android:gravity="center"
        android:id="@+id/gv"
        android:columnWidth="120dp"
        android:verticalSpacing="120dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </GridView>

</RelativeLayout>

MainActivity.java
```package com.example.photo;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

private int[]  pictures = new int[]{
                                      R.drawable.apple1,R.drawable.grape,
                                      R.drawable.kiwi,R.drawable.orange1,
                                      R.drawable.strawberry,R.drawable.subak};
}

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

    GridView gv = super.findViewById(R.id.gv);
    gv.setAdapter(new ImageAdapter(this));

}
public class ImageAdapter extends BaseAdapter
{
    mContext = c;
}
@Override
public int getCount() {
    return pictures.length;
}
@Override
public Object getItem(int position) {
    return null;
}
@Override
public long getItemId(int position) {
    return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    ImageView imageView
    if (convertView == null)
    {
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(100, 90));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    }
    else
    {
        imageView = (ImageView) convertView;
    }
    imageView.setImageResource(pictures[position]);
    return imageView;
}

}

1个回答

weixin_44587339
weixin_44587339 那dialog和strings.xml这两个要怎么写啊大神
3 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问