당신은 또한 다음과 같은 방법을
layout.xml to some extent like this...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="#000"
tools:context="com.example.tistis.myapplication.MainActivity">
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="2"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
하고 ImageAdapter.java
을 다음과 같이 할 수있는 일은 코드입니다. 어댑터에서 코드를 작성하는 것은 더러운 방법이므로보기가 부풀려 져야합니다.
class ImageAdapter extends BaseAdapter {
private Context mContext;
public int screenHeight,screenWidth;
public ImageAdapter(Context c) {
mContext = c;
DisplayMetrics displaymetrics = new DisplayMetrics();
((Activity)c).getWindowManager().
getDefaultDisplay().getMetrics(displaymetrics);
screenHeight = displaymetrics.heightPixels;
screenWidth = displaymetrics.widthPixels;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(final int position,
View convertView, ViewGroup parent) {
ImageView imageView=null;
RelativeLayout frm;
SeekBar seekBar=null;
if (convertView == null) {
// if it's not recycled, initialize some attributes
frm= new RelativeLayout(mContext);
frm.setLayoutParams(new GridView.LayoutParams(screenWidth/2-(8*2+10),screenWidth/2-(8*2+10)));
frm.setPadding(8, 8, 8, 8);
frm.setBackgroundColor(Color.BLACK);
imageView = new ImageView(mContext);
imageView.setLayoutParams(
new FrameLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setBackgroundColor(Color.BLACK);
frm.addView(imageView);
imageView.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(mContext,
"Item position "+(position+1),
Toast.LENGTH_SHORT).show();
}
});
seekBar=new SeekBar(mContext);
seekBar.setLayoutParams(
new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT, 40));
RelativeLayout.LayoutParams lp=
(RelativeLayout.LayoutParams)
seekBar.getLayoutParams();
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
seekBar.setMax(15);
// seekBar.setIndeterminate(true);
ShapeDrawable thumb =
new ShapeDrawable(new OvalShape());
thumb.setIntrinsicHeight(80);
thumb.setIntrinsicWidth(30);
seekBar.setThumb(thumb);
seekBar.setProgress(1);
seekBar.setVisibility(View.VISIBLE);
seekBar.setBackgroundColor(Color.TRANSPARENT);
frm.addView(seekBar);
} else {
frm = (RelativeLayout) convertView;
}
if(imageView!=null)
imageView.setImageResource(mThumbIds[position]);
return frm;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.superman, R.drawable.superman,
R.drawable.superman, R.drawable.superman,
};
}
감사합니다. 그런 다음 해당 FrameLayout 태그 안에 모든 ImageView를 넣을 수 있습니까? – AndyCr15
방금 이걸 시도해 보았습니다. 그 코드는 모든 종류의 오류를줍니다 ...? '레이아웃 높이를 정의해야합니다' – AndyCr15
프레임 레이아웃의 높이와 너비를 설정하고 버튼을 버튼 태그 안에 넣으십시오. –