我有这个xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/FrameLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="bottom"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="10dp"
android:orientation="vertical" >
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:id="@+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="@+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_gravity="bottom" >
<ImageView
android:id="@+id/right"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignTop="@+id/down"
android:layout_toRightOf="@+id/down"
android:src="@drawable/right" />
<ImageView
android:id="@+id/left"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignTop="@+id/down"
android:layout_toLeftOf="@+id/down"
android:src="@drawable/left" />
<ImageView
android:id="@+id/up"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/right"
android:src="@drawable/up" />
<ImageView
android:id="@+id/down"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_below="@+id/up"
android:layout_centerHorizontal="true"
android:src="@drawable/down" />
</RelativeLayout>
</LinearLayout>
我想在类中的LinearLayout surface
边框上绘制一些东西
我已经在课堂上控制了布局:
LinearLayout surface = new LinearLayout(this);
surface = (LinearLayout)findViewById(R.id.surface);
那么如何获得布局边框的坐标? Tnx的帮助:D
答案 0 :(得分:0)
使用MarginParam获取像素
中的边距边框View view = findViewById(R.layout.main) //or however you need it
LayoutParams l = (LayoutParams) view.getLayoutParams();
l.leftMargin;
l.rightMargin;
l.topMargin;
l.bottomMargin;
或使用getLocationOnScreen(View)在屏幕上计算此视图的坐标