3
RelativeLayoutの幅と高さを取得できません。どのように取得できますか?マイlayout.xmlファイルはRelativeLayoutの幅と高さを取得するには
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/layoutMain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="50dp" >
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
であり、私はちょうど、誰もがこの問題で私を助けることができる内蔵の提供方法のように、
public class CustomShowcaseActivity extends Activity { static float width;
static float height; RelativeLayout relMain;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_showcase);
relMain= (RelativeLayout) findViewById(R.id.layoutMain);
width = relMain.getMeasuredWidth();
height = relMain.getMeasuredHeight();
width = relMain.getWidth();
height = relMain.getHeight();
System.out.println("=== Width : " + width);
System.out.println("=== height : " + height);
} }
を使用してprogramtically RelativeLayoutの高さと幅を取得します?
を使用してみてください。 –
'オーバーライド' onWindowFocusedChanged'を参照してください。 –
@GauravMandlikは働いているか、私に知らせていませんか? –