【发布时间】:2015-06-30 13:38:44
【问题描述】:
我在另一个相对布局中有一个相对布局。当我使用内部布局作为线性布局时,代码工作正常。我在 SO 上读到了很多这样的questions。有时有人提到使用的布局参数应该属于父布局。我无法完全理解它。这是我出错的地方吗?
提前谢谢大家!
我的 XML 文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/rel1" >
<RelativeLayout
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="20dp"
android:src="@drawable/helo" />
</RelativeLayout>
</RelativeLayout>
我使用边距的功能
public void showcopter()
{
ImageView image=(ImageView)findViewById(R.id.imageView1);
RelativeLayout.LayoutParams lp=(RelativeLayout.LayoutParams)(image.getLayoutParams());
lp.leftMargin =0;//(int)((width-150)*density);
lp.topMargin=(int)(hg-(30*density)); //hg is a global variale which stores the screen height
// Log.d("hello_girl",hg+" ");
// lp.setMargins((int) ((width-150)*density),(int)(hg-(30*density)),0,0);
image.setLayoutParams(lp);
image.requestLayout();
}
【问题讨论】: