weixin_44587339
weixin_44587339
2019-10-26 20:46

求助android studio 相册类应用的编写

  • android-studio
  • xml
  • android

图片说明图片说明由于是在国外上学所以上课老师讲的操作可以跟上但是还是有些地方没有听明白,作业要让用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"?>
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>


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条回答

为你推荐

换一换