Created
June 24, 2013 18:06
-
-
Save masarugen/5852132 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.samplescrollview; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.graphics.Point; | |
import android.graphics.Rect; | |
import android.os.Bundle; | |
import android.util.DisplayMetrics; | |
import android.util.Log; | |
import android.view.Display; | |
import android.view.Menu; | |
import android.view.View; | |
import android.view.WindowManager; | |
public class MainActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// | |
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE); | |
// ディスプレイのインスタンス生成 | |
Display disp = wm.getDefaultDisplay(); | |
Log.d("hashizume", disp.getHeight() + ":" + disp.getWidth()); | |
} | |
/** | |
* 画面の高さを出す 対象レイヤーの高さを出す(LinerLayoutだからいつやるべきか?) 対象レイヤーのマージンでずらす | |
*/ | |
public void onImageClick(View view) { | |
View item = findViewById(R.id.item); | |
if (item.getVisibility() == View.GONE) { | |
item.setVisibility(View.INVISIBLE); | |
} else if (findViewById(R.id.item).getVisibility() == View.INVISIBLE) { | |
item.setVisibility(View.VISIBLE); | |
} else { | |
item.setVisibility(View.GONE); | |
} | |
Log.d("hashizume", findViewById(R.id.out).getBottom() + ":" | |
+ findViewById(R.id.out).getHeight()); | |
Log.d("hashizume", findViewById(R.id.scrollView).getBottom() + ":" | |
+ findViewById(R.id.scrollView).getHeight()); | |
Log.d("hashizume", findViewById(R.id.main).getBottom() + ":" | |
+ findViewById(R.id.main).getHeight()); | |
WindowManager wm = (WindowManager) getApplicationContext().getSystemService( | |
Context.WINDOW_SERVICE); | |
Display display = wm.getDefaultDisplay(); | |
DisplayMetrics displayMetrics = new DisplayMetrics(); | |
display.getMetrics(displayMetrics); | |
Log.v("widthPixels", String.valueOf(displayMetrics.widthPixels)); | |
Log.v("heightPixels", String.valueOf(displayMetrics.heightPixels)); | |
Log.v("xdpi", String.valueOf(displayMetrics.xdpi)); | |
Log.v("ydpi", String.valueOf(displayMetrics.ydpi)); | |
Log.v("density", String.valueOf(displayMetrics.density)); | |
Log.v("scaledDensity", String.valueOf(displayMetrics.scaledDensity)); | |
Log.v("width", String.valueOf(display.getWidth())); // 非推奨 | |
Log.v("height", String.valueOf(display.getHeight())); // 非推奨 | |
Log.v("orientation", String.valueOf(display.getOrientation())); // 非推奨 | |
Log.v("refreshRate", String.valueOf(display.getRefreshRate())); | |
Log.v("pixelFormat", String.valueOf(display.getPixelFormat())); | |
Log.v("rotation", String.valueOf(display.getRotation())); | |
// ここでステータスバーの高さが分かる | |
Rect rectgle = new Rect(); | |
getWindow().getDecorView().getWindowVisibleDisplayFrame(rectgle); | |
int statusBarHeight = rectgle.top; | |
Log.d("hashizume", rectgle.bottom + ":" + statusBarHeight); | |
Point real = new Point(0, 0); | |
// Android 4.2以上 | |
display.getRealSize(real); | |
android.util.Log.d("hashizume", rectgle.bottom + ":" + real.y); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.main, menu); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment