1
私の高さと幅を取得する必要があります。ここで示した例をサブクラス化して表示し、onSizeChanged(...)を使用しています。 しかし、どのような非常に奇妙であることonSizeChangedは私に正しい幅を与えることですが、高さがここで常に0である私のサブクラスです:onSizeChangedは幅を返しますが高さは返しません
public class MyView extends TextView {
int xMax=0; int yMax=0;Context c;
public MyView(Context context) {
super(context);
this.c=context;
}
@Override
public void onSizeChanged(int w, int h, int oldW, int oldH) {
xMax = w;
yMax = h;
マイActivityクラス:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView dummyView = new MyView(this);
LinearLayout ll = (LinearLayout) findViewById(R.id.mainmtc);
ll.addView(dummyView);
と私のXMLレイアウト:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainmtc" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="1"
androiad:orientation="vertical">
は(私はStackOverflowのに新しいです)尽くします。しかし、私の問題の解決策は何ですか?これが起こったと言われる例はありませんか? – michaelsmith
今は、高さはまだ0です。デバイスを回転させると幅が変わりますが、高さは変わりません。私はデバイス画面の寸法を取得する必要があります。私は正しいアプローチをしていますか? – michaelsmith
DisplayMetricsクラスでデバイスの画面サイズを取得することができます – ChristopheCVB