저는 최근 Studio에서 Android 개발을 시작했으며 카메라를 사용하여 사진을 클릭하고 해당 앱의 갤러리에 표시 할 수있는 앱을 만들려고합니다. 요즘은 모든 사진 앱처럼 기본적인 상황입니다. 카메라와 갤러리는 그 앱 자체가 클릭 한 사진을 보여줍니다.android studio를 사용하는 동안 gridView에 이미지가 나타남
나는 카메라를 통합 관리했으며 지금 갤러리 부분을 작업 중입니다. 그리드 뷰를 사용하여 갤러리 액티비티의 레이아웃을 만들었지 만, 이미지가 조금 우연히 나오기 때문에 제대로 작동하지 않습니다. 내 응용 프로그램이 충돌을 일으키는 때문에 나는 선)합니다 (image.setLayoutParams을 주석 한
public class GridViewAdapter extends BaseAdapter {
// Declare variables
private Activity activity;
private String[] filepath;
private String[] filename;
private static LayoutInflater inflater = null;
public GridViewAdapter(Activity a, String[] fpath, String[] fname) {
activity = a;
filepath = fpath;
filename = fname;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return filepath.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null)
vi = inflater.inflate(R.layout.grid_item_layout, null);
// Locate the ImageView in gridview_item.xml
ImageView image = (ImageView) vi.findViewById(R.id.image);
//image.setLayoutParams(new GridView.LayoutParams(215, 215));
image.setPadding(8, 8, 8, 8);
// Decode the filepath with BitmapFactory followed by the position
Bitmap bmp = BitmapFactory.decodeFile(filepath[position]);
// Set the decoded bitmap into ImageView
image.setImageBitmap(bmp);
return vi;
}
}
-
은 아래의 "GridViewAdapter.java"내 코드입니다.
그리고 이것은 해당 .XML 파일입니다 -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip" >
<GridView
android:id="@+id/gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="3"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="spacingWidthUniform"
android:gravity="center"/>
</RelativeLayout>
내가 갖는 출력은 - screenShot of the app
가 난 단지 이번 주 애플 리케이션을 개발하기 시작, 그래서에 매우 감사합니다 여기에 제공된 도움.
감사합니다.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dip" >
<ImageView
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/image" />
</RelativeLayout>
grid_item_layout.xml 소스 코드도 추가하십시오. –
@RahulKumar –