getViewId(RelativeLayout rl) は、RelativeLayout 内の子のビュー(Id)を調査して最大値を返す。IDを利用して相対位置を指定するので、数字を昇順にセットして利用したい。また、タップした時の処理でIDが並んでいれば、計算でindexナンバーを求められる。textView配列にindex指定でストリングを引き出せば、ファイルネームを分かる。
後編。
public int getSize() {
return thumbnailImage.size();
}
public int getThumbnailWidth() {
return THUMBNAIL_WIDTH;
}
public int getThumbnailHeight() {
return THUMBNAIL_HEIGHT;
}
private void getScreenSize( Context c ) {
WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
WindowMetrics mWindowMetrics = wm.getMaximumWindowMetrics();
mScreenWidth = mWindowMetrics.getBounds().width();
mScreenHeight = mWindowMetrics.getBounds().height();
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
DisplayMetrics mDisplayMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getRealMetrics(mDisplayMetrics);
mScreenWidth = mDisplayMetrics.widthPixels;
mScreenHeight = mDisplayMetrics.heightPixels;
return;
}
Point realSize = new Point();
wm.getDefaultDisplay().getSize(realSize);
mScreenWidth = realSize.x;
mScreenHeight = realSize.y;
}
private int getViewId(RelativeLayout rl) {
int id, ret = 0;
if ( rl instanceof ViewGroup ) {
for ( int i=0; i < rl.getChildCount(); i++ ) {
id = rl.getChildAt(i).getId();
if ( id > ret ) ret = id;
}
}
return ret;
}
}