내 GridView
자체가 중앙에 배치되어 있지만 내용이 중앙에 있지 않습니다. 다음은 화면입니다. 아래쪽과 오른쪽의 하늘색은 GridView
의 배경색입니다.GridView의 내용 가운데 가운데에
당신은 내용이 맨 왼쪽까지 밀어 것을 볼 수 있습니다. 내 게임 보드의 내용이 정확히 GridView
의 가운데에 있고, 밝은 파란색 배경색이 모든면을 동일하게 둘러 쌉니다. 도움이된다면 내 ImageAdapter
클래스
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/textFieldFU"
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"
tools:context=".MainActivity" >
<GridView
android:id="@+id/gridview"
android:layout_marginTop="0dp"
android:layout_marginLeft="45dp"
android:layout_marginRight="45dp"
android:layout_width="fill_parent"
android:layout_height="485dp"
android:gravity="center"
android:horizontalSpacing="0dp"
android:numColumns="8"
android:background="@android:color/holo_blue_bright"
android:verticalSpacing="0dp" />
그리고 내 getView
:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView iv;
if (convertView != null) {
iv = (ImageView) convertView;
} else {
iv = new ImageView(context);
iv.setLayoutParams(new GridView.LayoutParams(60, 60));
iv.setScaleType(ScaleType.FIT_CENTER);
iv.setPadding(0, 0, 0, 0);
if(position < 8 && position % 2 ==0){
iv.setBackgroundColor(Color.DKGRAY);
}
else if(position > 7 && position < 16 && position % 2 ==1){
iv.setBackgroundColor(Color.DKGRAY);
}
else if(position > 15 && position < 24 && position % 2 ==0){
iv.setBackgroundColor(Color.DKGRAY);
}
else if(position > 23 && position < 32 && position % 2 ==1){
iv.setBackgroundColor(Color.DKGRAY);
}
else if(position > 31 && position < 40 && position % 2 ==0){
iv.setBackgroundColor(Color.DKGRAY);
}
else if(position > 39 && position < 48 && position % 2 ==1){
iv.setBackgroundColor(Color.DKGRAY);
}
else if(position > 47 && position < 56 && position % 2 ==0){
iv.setBackgroundColor(Color.DKGRAY);
}
else if(position > 55 && position < 64 && position % 2 ==1){
iv.setBackgroundColor(Color.DKGRAY);
}
else
iv.setBackgroundColor(Color.GRAY);
}
iv.setImageResource(images[position]);
return iv;
}
가능한 복제 [GridView 아래에있는 ImageView를 GridView의 크기와 정확히 일치시키는 방법?] (http://stackoverflow.com/questions/16339242/easy-way-to-make-an-imageview- 그 아래에있는 gridview-match-the-gridviews) – Raghunandan