【发布时间】:2014-08-15 21:45:00
【问题描述】:
这是我的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 和图像视图的位置,并指导我在扩展主体时做错了什么。
【问题讨论】:
-
您必须使用 LayoutParams,我认为 [This][1] 链接会对您有所帮助。 [1]:stackoverflow.com/questions/6607190/…
-
你到底想做什么?你确定不能只使用xml吗?
-
使用线性布局。使用权重可以正确完成。
标签: android android-layout margins