这是我的xml文件,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white" >
<TextView
android:id="@+id/datetitle"
android:layout_width="wrap_content"
android:layout_height="80dp"
/>
<ImageView
android:id="@+id/meetingline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="@drawable/meetingline"
android:layout_marginLeft="60dp"
android:layout_toRightOf="@+id/datetitle"
android:visibility="gone" />
</RelativeLayout>
这是java ..
中的代码RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mViewHolder.startDate.getLayoutParams();
RelativeLayout.LayoutParams paramsImage = (RelativeLayout.LayoutParams) imgView.
double conversion = minute*2.7;
int topmargin = (int)conversion;
// params.setMargins(0,topmargin,0,0);
params.topMargin = topmargin;
paramsImage.topMargin = topmargin+15;
SimpleDateFormat df = new SimpleDateFormat("h:mm a");
String date = df.format(Calendar.getInstance().getTime());
if(hour == myList.get(position).getPosition())
{
mViewHolder.startDate.setLayoutParams(params);
mViewHolder.startDate.setTextColor(Color.BLUE);
mViewHolder.startDate =detail(convertView, R.id.datetitle, date);
if(imgView != null)
imgView.setLayoutParams(paramsImage);
imgView.setVisibility(1);
imgView.bringToFront();
}
else{
params.topMargin=0;
mViewHolder.startDate.setLayoutParams(params);
mViewHolder.startDate.setTextColor(Color.BLACK);
imgView.setVisibility(View.INVISIBLE);
}
我正在做的是我通过设置它们的上边距来设置textview和图像在相对布局中的位置,但是它没有正常工作有一些出错的地方,它延伸了行体,你可以看到我已经附上了这篇文章的图片中的4,请指导我如何通过不扩展行的主体来设置textview和图像视图的位置,并指导我通过它扩展身体我做错了什么。{{0} }
答案 0 :(得分:0)
试试这个
TextView widget = new TextView(screenContext);
widget.setText("Label");
widget.setLayoutParams(newAbsoluteLayout.LayoutParams(width,height,calculatedX,calculatedY));