0
나는 android에서 강의를 듣고 있으며, TabLayout
을 보여주는 샘플 애플리케이션이 있습니다. 응용 프로그램에는 꽃의 이미지가있는 두 개의 탭이 있고 개 이미지가있는 두 번째 탭이 있습니다. 둘 다 그리드 뷰로 구성됩니다. 탭을 변경할 때마다 코드에서 사진으로 채워진 적절한 조각으로 fragment_container
을 변경합니다.gridview의 이미지가 겹칩니다.
그러나 앱 이미지를 실행할 때 서로 겹칩니다. 나는 무엇이 잘못 되었는가를 모른다 - 나는 stretchMode
등과 같은 어떤 속성을 변경하려했지만 도움이되지 않았다.
강사가 보니이 장치에 행 당 최대 3 개의 이미지가 표시되어야합니다.
main.xml에
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
grid_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:verticalSpacing="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="XXXXX" >
</TextView>
</LinearLayout>
업데이트. 어댑터
public class ImageAdapter extends BaseAdapter {
private static final int PADDING = 8;
private static final int WIDTH = 250;
private static final int HEIGHT = 250;
private Context mContext;
private List<Integer> mThumbIds;
public ImageAdapter(Context c, List<Integer> ids) {
mContext = c;
this.mThumbIds = ids;
}
@Override
public int getCount() {
return mThumbIds.size();
}
@Override
public Object getItem(int position) {
return null;
}
// Will get called to provide the ID that
// is passed to OnItemClickListener.onItemClick()
@Override
public long getItemId(int position) {
return mThumbIds.get(position);
}
// create a new ImageView for each item referenced by the Adapter
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = (ImageView) convertView;
// if convertView's not recycled, initialize some attributes
if (imageView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(WIDTH, HEIGHT));
imageView.setPadding(PADDING, PADDING, PADDING, PADDING);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
}
imageView.setImageResource(mThumbIds.get(position));
return imageView;
}
}
설정 '이미지 뷰의 안드로이드 코딩되지 않도록 어댑터에서의 getView 방법을 업데이트하십시오 : scaleType = "centerCrop"안드로이드 : adjustViewBounds = "true"' –
@MD'ImageView'는 프로그래밍 방식으로 만들어졌고, 나는 어댑터로 포스트를 업데이트하고 어떻게 만들어 졌는지 보여줍니다. 'scaleType'이'centerCrop'으로 설정되었지만'adjustViewBounds'를 어떻게 설정해야할지 모르겠습니다. – ashur
@ashut imageView.setadjustViewBounds (true) 및 scaletype도 설정하십시오. –